none
Is it possible to get the type name of a specific method in the assembly? RRS feed

  • Question

  • My assembly contain multiple types, e.g. Namespace.Class1, Namespace.Class2, Namespace.Class3

     

    Is it possible to find out which types the method, foo(), belongs to in the assembly?

     

     

    Sunday, February 17, 2008 1:50 PM

Answers

  • Yes it is possible.  Using reflection you could query each type and each method in that type.  Something like this:

     

    Code Snippet

    List<Type> types = new List<Type>();

    System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoad("assembly.dll");

    foreach(Type t in a.GetTypes())

    {

    foreach (System.Reflection.MemberInfo method in t.GetMethods())

    {

    if (method.Name == "Foo")

    {

    types.Add(t);

    }

    }

    }

    }

     

     

     

    Sunday, February 17, 2008 5:11 PM

All replies

  • Yes it is possible.  Using reflection you could query each type and each method in that type.  Something like this:

     

    Code Snippet

    List<Type> types = new List<Type>();

    System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoad("assembly.dll");

    foreach(Type t in a.GetTypes())

    {

    foreach (System.Reflection.MemberInfo method in t.GetMethods())

    {

    if (method.Name == "Foo")

    {

    types.Add(t);

    }

    }

    }

    }

     

     

     

    Sunday, February 17, 2008 5:11 PM
  • Thanks Dan.

     

    Monday, February 18, 2008 4:32 AM