c# - 使用类名获取用于我们项目的引用 dll 名称

标签 c# .net dll namespaces .net-assembly

你如何获得所有引用 dll 名称及其代表类名称以及 C# 中特定 dll 反射中使用的命名空间?

让我们考虑sample.dll,其中reference1.dll和reference2.dll通过方法reference1.method1和reference2.method2作为对示例dll的引用

我需要列出

1)reference dll names ie.reference1.dll,reference2.dll
2)methods used in that dll names ie.reference1.method1,reference2.method2
3) Namespace used for referring that reference dll

我试过 myassembly.GetTypes()这对我没有帮助

等待你的回应

最佳答案

嗯,我不知道你为什么这么想 Assembly.GetTypes()没有帮助...

请注意,并非所有 dll 都在磁盘上,因此如果您 Assembly.Location而不是名称,那么您可能会遇到错误。

命名空间不引用特定的程序集,一个程序集可以包含许多命名空间。

下面的方法将包含相当一部分 .Net 框架,因此您可能需要稍微过滤一下列表。

这有帮助吗?

        List<String> Dlls = new List<string>();
        List<String> Namespaces = new List<string>();
        List<String> Methods = new List<string>();
        foreach (var Assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (!Dlls.Contains(Assembly.GetName().Name))
                Dlls.Add(Assembly.GetName().Name);

            foreach (var Type in Assembly.GetTypes())
            {
                if (!Namespaces.Contains(Type.Namespace))
                    Namespaces.Add(Type.Namespace);
                foreach(var Method in Type.GetMethods())
                {
                    Methods.Add(String.Format("{0}.{1}", Type.Name, Method.Name));
                }
            }

        }

关于c# - 使用类名获取用于我们项目的引用 dll 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787365/

相关文章:

c# - 我要对其进行字符串搜索的 4000 个文件

c# - 是否可以在命令行或通过配置文件添加 "InternalsVisibleTo"的包?

c# - 针对 .net core RC2 和 .net4.6.1 时出错

dll - LoadLibrary() - "Invalid Access Memory Location (998)"

.net - OpenCV - 缺少 dll

c# - 获取执行指令数的方法是什么?

c# - 如何通过 SSH.NET 在远程服务器上运行 mysqldump 而不会出现密码警告?

c# - 如何保护 WinForms ConnectionString

c++ - 'operator new' : redefinition, 不同的链接(在重新定义的新运算符上使用 _dllspec)

c# - 加载程序集、查找类和调用 Run() 方法的正确方法