三种用反射的方法获得instance实例
// 三种用反射的方法获得instance实例。
public static AbstractFactory GetFactoryInstance()
{
string factoryName = Constant.STR_FACTORYNAME.ToString();
AbstractFactory instance;
if (factoryName != "")
//instance = (AbstractFactory)Assembly.Load("AbstractFactory").CreateInstance(factoryName);
{
//Type type = Type.GetType(factoryName);
//instance = (AbstractFactory)Activator.CreateInstance(type);
Type type = Type.GetType(factoryName);
//ConstructorInfo constructor = type.GetConstructor(new Type[0]);
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
instance = (AbstractFactory)constructor.Invoke(null);
}
else
instance = null;
return instance;
}