开发者

How I do add this function to console app

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 me开发者_运维技巧thods from that class.

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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜