views:

72

answers:

1

Hello, I have loaded an assembly called 'Mscorlib.dll' and i wanted it to list all classes within the 'Mscorlib', which it does(using reflection). Now I want to add a function whereby the user inputs a class from the assembly and it gets all the methods from that class.

How would i go around doing this? Any help would be nice

+1  A: 

Use Assembly.GetType(type) to get the appropriate Type, then Type.GetMethods to get the methods within it. (Note that the overload which doesn't take a BindingFlags will only return public methods.)

For example (no error checking):

Assembly mscorlib = typeof(int).Assembly;
Console.Write("Type name? ");
string typeName = Console.ReadLine();
Type type = mscorlib.GetType(typeName);
foreach (MethodInfo method in type.GetMethods())
{
    Console.WriteLine(method);
}
Jon Skeet
Yes, I have already done this Jon but now I want the user to search the mscorlib for a class and that will show the methods of that class chosen. I do not want a full list of methods for the mscorlib as it seems there is too much information.
MW
Um, that's exactly what I've shown you - note the call to `Assembly.GetType(string)` rather than `Assembly.GetTypes()`. Just call GetMethods on a *single type* rather than every type within the assembly.
Jon Skeet
That really helped thank you!
MW