Type.GetType()
程序员文章站
2022-04-10 19:13:26
...
// .net code
private Type GetType(string className)
{
// Creates current domain.
AppDomain currentDomain = AppDomain.CurrentDomain;
// Makes an array for the list of assemblies.
Assembly[] assems = currentDomain.GetAssemblies();
Type type = null;
for (int j = 0; j < assems.Length; j++)
{
Type[] types = assems[j].GetTypes();
for (int k = 0; k < types.Length; k++)
{
if (types[k].Name.Equals(className) || (types[k].FullName.Equals(className)))
{
type = types[k];
break;
}
}
if (type != null)
{
break;
}
}
return type;
}
private Type GetType(string className)
{
// Creates current domain.
AppDomain currentDomain = AppDomain.CurrentDomain;
// Makes an array for the list of assemblies.
Assembly[] assems = currentDomain.GetAssemblies();
Type type = null;
for (int j = 0; j < assems.Length; j++)
{
Type[] types = assems[j].GetTypes();
for (int k = 0; k < types.Length; k++)
{
if (types[k].Name.Equals(className) || (types[k].FullName.Equals(className)))
{
type = types[k];
break;
}
}
if (type != null)
{
break;
}
}
return type;
}
上一篇: 使用对象封装ajax重复调用的方法