如何在C#中获取所有引用dll名称及其表示类的名称空间,特别是dll反射?
让我们考虑一下sample.dll,其中使用了reference1.dll和reference2.dll作为通过方法reference1.method 1和reference2.method 2对示例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()试过了,它对我没有帮助
等待你的回复
发布于 2013-04-03 20:46:16
我不明白你为什么觉得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));
}
}
}https://stackoverflow.com/questions/15787365
复制相似问题