我有一个项目,我在另一个项目bin目录上搜索,目的是编写每个程序集中的所有方法:
public static List<ManagerMethodDescr> getManagerMethodDescr(string nomeClasse)
{
DirectoryInfo inf = new DirectoryInfo(@"C:\NETASUITE\Backend\NETASIAL\Business\Managers.Common\bin");
FileInfo[] fileDll = inf.GetFiles("*.dll");
List<ManagerMethodDescr> ManagerDesc = new List<ManagerMethodDescr>();
foreach (FileInfo fi in fileDll)
{
Assembly newAss = Assembly.LoadFile(fi.FullName);
try
{
foreach (Type tipo in newAss.GetTypes())
{
if (tipo.Name == nomeClasse)
{
MethodInfo[] mis = tipo.GetMethods();
foreach (MethodInfo mi in mis)
{
IEnumerable<CustomAttributeData> ieC = mi.CustomAttributes;
string arg = "";
if (ieC.Count() > 0)
{
if (ieC.ElementAt(0).ConstructorArguments.Count > 0)
{
arg = ieC.ElementAt(0).ConstructorArguments[0].ToString().Replace("\"", "");
}
}
if (mi.IsPublic && arg == "Interfaccia")
{
MethodAttributes ma = mi.Attributes;
string ritorno = mi.ReturnType.Name.ToString();
string name = mi.Name;
ParameterInfo[] pi = mi.GetParameters();
List<string[]> Param = new List<string[]>();
foreach (ParameterInfo ppi in pi)
{
Param.Add(new string[] { ppi.Name, ppi.ParameterType.Name.ToString() });
}
ManagerDesc.Add(new ManagerMethodDescr(ritorno, name, Param, mi.ReturnType.Namespace));
}
}
}
}
}
catch (ReflectionTypeLoadException e)
{
IEnumerable<Type> iet= e.Types.Where(t => t != null);
}
}
return ManagerDesc;
}
对于某些程序集我得到错误,如#34;无法加载类型&#39; NETA.SUITE.SIAL.Tipi.Base.SialBaseType&#39;来自汇编&#39; NETA.SUITE.SIAL.Tipi.Base&#34; (当我执行newAss.GetTypes()时给出例外)即使引用写得很好并且都设置为复制本地真...我无法摆脱它... .i尝试了一个简单的项目,我的目的是为了它的目的而且它有用......