【问题标题】:Get reference dll name used for our project with class name使用类名获取用于我们项目的参考 dll 名称
【发布时间】:2013-03-25 02:52:49
【问题描述】:

如何获取所有引用 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() 它对我没有帮助

等待您的回复

【问题讨论】:

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


【解决方案1】:

嗯,我不确定你为什么认为 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));
                }
            }

        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 2016-12-07
    • 1970-01-01
    相关资源
    最近更新 更多