我在考虑一种通用的方法,其中T应该是接口,但它可以是IFace的子类。
public static T Get<T>(SomeClass foo) where T : IFace {
if(smthing)
return Activator.CreateInstance(type, true);
}
所以我可以调用
Class.Get<IFace>(smth)
Class.Get<IFaceDescend>(smt)
但不是
Class.Get<Class2>(smt)