如何检索* .DLL所有公共方法 [英] How to retrieve all public methods from *.dll

查看:146
本文介绍了如何检索* .DLL所有公共方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的* .dll用C#,我需要得到包含在* .dll文件的所有公共方法或类列表。是否有某种方式与C#编程做呢?

I have *.dll written with C# and I need to get list of all public methods or classes contained in that *.dll. Is there some way to do it programmatically with C#?

推荐答案

是使用<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes.aspx">Assembly.GetTypes提取所有类型,然后使用反射在每个类型重复的公共方法。

Yes use Assembly.GetTypes to extract all of the types, and then use reflection on each type to iterate the public methods.

Assembly a = Assembly.LoadWithPartialName("...");
Type[] types = a.GetTypes();
foreach (Type type in types)
{
    if (!type.IsPublic)
    {
        continue;
    }

    MemberInfo[] members = type.GetMembers(BindingFlags.Public
                                          |BindingFlags.Instance
                                          |BindingFlags.InvokeMethod);
    foreach (MemberInfo member in members)
    {
        Console.WriteLine(type.Name+"."+member.Name);
    }
}

这篇关于如何检索* .DLL所有公共方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆