根据类名创建类的步骤
通过类类型创建类对象
public static MenuCommand CreateMenuCommandVehicle(Type vehicleType)
{ System.Reflection.ConstructorInfo construct = vehicleType.GetConstructor(Type.EmptyTypes); MenuCommand v = (MenuCommand)construct.Invoke(null); return v; }*********************************************************************************************
根据类名创建子类
MenuCommand 要创建的类的父类类型
strClassName 要创建的类的类名 从命名空间开始的完整的类名
public static MenuCommand CreateMenuCommandVehicle(string strClassName)
{ try { System.Typetype=System.Type.GetType(strClassName,true);System.Reflection.ConstructorInfo construct =type.GetConstructor(Type.EmptyTypes);
MenuCommand v = (MenuCommand)construct.Invoke(null); return v; } catch(Exception ex) { throw( new Exception(ex.Message)); }}