I was thinking of a generic method where T should be interface but it can be the descendant of IFace
public static T Get<T>(SomeClass foo) where T : IFace {
if(smthing)
return Activator.CreateInstance(type, true);
}
so i can call
Class.Get<IFace>(smth)
Class.Get<IFaceDescend>(smt)
but not
Class.Get<Class2>(smt)
No, you can’t do this. You can test for it at execution time:
… but you can’t express it as a compile-time constraint on
T.