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

  • SEARCH
  • Home
  • 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 8878157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:38:49+00:00 2026-06-14T19:38:49+00:00

Assume I have a class like so: public class MyClass<T> { public void Foo(T

  • 0

Assume I have a class like so:

public class MyClass<T>
{
    public void Foo(T t)
    {
    }
}

Now, assume, I have an instance of MyClass<int> and a MethodInfo of its Foo method.
Calling methodInfo.GetParameters() will return a ParameterInfo array with one entry, referring to type int. My problem is, that I can’t seem to find out, if that parameter was declared as int in the class or as T.

What am I trying to achieve?
At runtime, I want to read the documentation of the method specified by MethodInfo from the XML Doc file generated by Visual Studio.
For the above defined method, the key looks like this:

<namespace>.MyClass`1.Foo(`0)

The `0 refers to the first generic type parameter of the declaring class. To be able to construct this string, I need to somehow get this information.
But how? MethodInfo doesn’t seem to contain that info…

  • 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-06-14T19:38:51+00:00Added an answer on June 14, 2026 at 7:38 pm

    The key seems to be Type.ContainsGenericParameters on the parameter type:

    Given

    public class MyClass<T>
    {
        public void Foo(T t)
        {
        }
    
        public void Bar(int i)
        {
    
        }
    }
    

    Then

    class Program
    {
        static void Main(string[] args)
        {
            var obj = new MyClass<int>();
    
            // Closed type
            var closedType = obj.GetType();
    
            // Open generic (typeof(MyClass<>))
            var openType = closedType.GetGenericTypeDefinition();
    
            // Methods on open type
            var fooT = openType.GetMethod("Foo");
            var barint = openType.GetMethod("Bar");
    
            // Parameter types
            var tInFoo = fooT.GetParameters()[0].ParameterType;
            var iInBar = barint.GetParameters()[0].ParameterType;
    
            // Are they generic?
            var tInFooIsGeneric = tInFoo.ContainsGenericParameters;
            var iInBarIsGeneric = iInBar.ContainsGenericParameters;
    
            Console.WriteLine(tInFooIsGeneric);
            Console.WriteLine(iInBarIsGeneric);
    
            Console.ReadKey();
        }
    }
    

    outputs

    True
    False
    

    This will obviously need more work for overloads and so on.

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

Sidebar

Related Questions

Alright, let's assume I have a class like the following ... public class Foo
Assume I have a class like this: public class Server { public static void
Assume I have a controller method like this: [Audit] public JsonNetResult List(int start, int
Let's assume I have an annotated bean property setter like this: public class Foo
Assume I have a class like this: public class Foo { public Bar RequiredProperty
Assume I have defined a class like this: class foo { private: std::vector< int*
Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume I have a class that looks like this: class Sample { public string
So I have a class that looks like this: internal class MyClass { public
So I have a class that looks something like the following: public class MyClass

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.