通过dll反射获得dll中有的逻辑类
2015-03-14 21:49:19 访问(2081) 赞(0) 踩(0)
/// <summary>
///
/// </summary>
/// <param name="fileName"></param>
protected void LoadClassName(string fileName)
{
if (fileName == null || fileName.Trim().Length == 0)
return;
try
{
string curClassName = comboBox_ClassName.Text.Trim();
Assembly ass = Assembly.LoadFile(fileName);
Type[] tArray = ass.GetTypes();
Type typeofUserControl = typeof(UserControl);
comboBox_ClassName.Items.Clear();
comboBox_ClassName.Items.Add("-");
bool isFind = false;
Type curType = null;
foreach (Type t in tArray)
{
if (t == null)
continue;
isFind = false;
curType = t;
while (true)
{
if (curType == null)
break;
if (curType == typeofUserControl)
{
isFind = true;
break;
}
curType = curType.BaseType;
}
if (isFind)
{
comboBox_ClassName.Items.Add(t.FullName);
}
}
comboBox_ClassName.Text = curClassName;
}
catch
{
}
}
上一条:
下一条:
相关评论
发表评论