谁能给一个以类型为参数传递的例子?多谢!
我想取一个类A的TYPE,然后再到另外的程序中以TYPE进行实例化,重新生成A,然后应用,谁能给一个例子啊?多谢!
------解决方案--------------------private object NewObject(Type AType, object AParent, string AText)
{
if (AType == null) return null;
object Result = Activator.CreateInstance(AType);
PropertyInfo vPropertyParent = AType.GetProperty( "Parent ");
if (vPropertyParent != null)
vPropertyParent.SetValue(Result, AParent, null);
PropertyInfo vPropertyText = AType.GetProperty( "Text ");
if (vPropertyText != null)
vPropertyText.SetValue(Result, AText, null);
return Result;
}
private void button1_Click(object sender, EventArgs e)
{
NewObject(button1.GetType(), this, "Zswang 路过 ");
}