读书人

发射达人请看类构造函数的一个参数

发布时间: 2013-01-27 13:56:15 作者: rapoo

发射达人请看——类构造函数的一个参数是类类型的,如何反射?
需要被反射的类是这样写的(片段)

namespace Cj.Bm.Forms
{
public partial class BM_Edit : BaseForm
{
......
public BM_Edit(string BM, BMSP Father)
{
Initialize();
_bm = BM;
father = Father;
this.Text = "编码添加";
......
}
......
}
}

我想反射调用这个类,但是构造函数BM_Edit的第二个参数Father是BMSP类型的,而BMSP是另外一个类,我使用
object formObj = Activator.CreateInstance(formType, new object[] { "001", form1Obj });
这句就会报错,其中form1Obj是我Activator.CreateInstance调用BMSP这个类得到的object

请教一下高手们这个该如何处理呢? C#?反射 CreateInstance
[解决办法]
 object formFather = Activator.CreateInstance(Type.GetType("Cj.Bm.Forms.BMSP"));

Form formObj = (Form)Activator.CreateInstance(Type.GetType("Cj.Bm.Forms.BM_Edit"), new object[] { "001", formFather });
formObj.ShowDialog();

读书人网 >C#

热点推荐