你如何获得所有引用 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/