您如何获得所有参考dll名称及其表示类名称与命名空间使用在特定的dll反射在c#中?
让我们考虑sample. DLL,其中reference1. DLL和reference2.dll通过方法reference1作为对样例DLL的引用。Method1和reference2
i need to list out
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
代替name,那么你可能会遇到一个错误。
命名空间不指向特定的程序集,一个程序集可以包含多个命名空间。
下面的方法将包含。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));
}
}
}