Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 522747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:23:11+00:00 2026-05-13T08:23:11+00:00

I’ve been working on an API that encapsulates another, trickier-to-use API. The goal is

  • 0

I’ve been working on an API that encapsulates another, trickier-to-use API. The goal is for my API to not require the user to touch any of the old API by 1) not requiring any parameters of classes in the old API and 2) not returning any instances of classes in the old API. Is there a program, perhaps a Visual Studio plugin, that can analyze my C# solution and give me a list of all the return types from publicly accessible methods in publicly accessible classes, as well as all the parameter types in such methods? Otherwise it seems like I’ll have to manually go through all my classes and see if any of the old API is exposed to the user.

Edit: Since I’ve been using MSTest for unit testing my API anyway, I added another unit test to use reflection and Fail if any parts of the old API are exposed. However, I’m stuck with a reflection problem. I have using OldAPI in the unit test class and then I use

AppDomain.CurrentDomain.GetAssemblies().SelectMany(
    assembly => assembly.GetTypes()
)

to get a list of the types in all the assemblies currently loaded. I then iterate over those in hopes of paring down the list of types to only those in the namespace OldAPI. The problem is that the namespace OldAPI does not show up. I see namespaces like Microsoft.VisualStudio.TestTools, System.Reflection, and others that are included via using statements in the test class, but no “OldAPI”. Could this be because of COM stuff with the old API, so AppDomain.CurrentDomain.GetAssemblies() doesn’t include the assembly even though it’s included via a using statement in the class?

Solution: I got the necessary assembly by arbitrarily choosing one class I know is in OldAPI and doing the following, thanks to SLaks‘ comment:

Func<Type, bool> isBad = t => t.Assembly == typeof(OldAPI.SomeClass).Assembly;

Here’s a snippet of my unit test for checking if any of my API’s classes use any of OldAPI‘s classes, thanks to SLaks‘ answer:

MethodInfo[] badMethods = methods.Where(
    m => (
             isBad(m.ReturnType) ||
             m.GetParameters().Any(p => isBad(p.ParameterType))
         ) && !isBad(m.DeclaringType)
).ToArray();
string[] badMethodNames = badMethods.Select(
    m => m.DeclaringType.Name + "." + m.Name
).Distinct().ToArray();
Assert.AreEqual(0, badMethodNames.Length, "Some methods in " +
    monitoredNamespaces + " projects expose OldAPI: " +
    string.Join(", ", badMethodNames));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:23:11+00:00Added an answer on May 13, 2026 at 8:23 am

    You can use LINQ, like this:

    Func<Type, bool> isBad = t => t.Assembly == badAssembly;
    
    var types = yourAssembly.GetTypes();
    var methods = types.SelectMany(t => t.GetMethods()).ToArray();
    
    var badMethods = methods.Where(m => isBad(m.ReturnType) 
        || m.GetParameters().Any(p => isBad(p.ParameterType);
    
    var properties = types.SelectMany(t => t.GetProperties()).ToArray();
    var badProperties = properties.Where(p => isBad(p.PropertyType));
    

    This would be easiest to do in LINQPad.

    Note that this doesn’t traverse generic types, so it’ll ignore a List<BadType>.
    You should probably make isBad recursive. (In which case you should turn it into a regular function)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.