日期:2014-05-17  浏览次数:20700 次

发射达人请看——类构造函数的一个参数是类类型的,如何反射?
需要被反射的类是这样写的(片段)
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();