`
coolerbaosi
  • 浏览: 727382 次
文章分类
社区版块
存档分类
最新评论

.NET 中反射传参问题

阅读更多

class Code:

public partial class baseForm : Form

{
public baseForm()
{
InitializeComponent();


}
public baseForm(int dd)
{
State = dd;

}

}

another class

//替换路径
string path = System.AppDomain.CurrentDomain.BaseDirectory + "TableList.dll";
//要下达的填写文件
Type[] types = Assembly.LoadFile(path).GetTypes();
////填写报表
foreach (Type var in types)
{
if (var.Name == str)
{

baseForm fm = (baseForm)Activator.CreateInstance(var,1);

fm.ShowDialog();

break;

}

}

多个参数:

(baseForm)Activator.CreateInstance(var, true, BindingFlags.CreateInstance,null, new object[] { "a", "b" },null, null);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics