0
我有一个项目,我想保留对Type
的引用,并且稍后将initalize该类型的实例。但我想要一些编译时类型检查,所以我只能提供实现ITest
接口的类型。我想我必须改变方法,但我看不出如何。检查一个接口是否在编译时通过一个类型实现
private static Type currentType = null;
public static void Initalize (Type current){
currentType = current;
}
public class Test : ITest{}
public class Test2 {}
应该可以在typeof(Test)
通过但不允许typeof(Test2)