c# - Is it possible to programmatically enforce a derived class to pass itself into a base class as the generic type? -
basically, have following scenario:
public abstract class foobase<t> t : foobase<t> { public bool isspecial { get; private set; } public static t getspecialinstance() { return new t() { isspecial = true }; } } public sealed class concretefooa : foobase<concretefooa> { ... } public sealed class concretefoob : foobase<concretefoob> { ... }
but, problem see here have done concretefoob : foobase<concretefooa> { ... }
, mess class @ runtime (it wouldn't meet logic i'm trying achieve), still compile correctly.
is there way haven't thought of enforce generic, t, whatever derived class is?
update: end using generic parameter, t, in foobase<t>
class, didn't list every method has out , in parameter, have use t.
to answer question:
no, there no compile time solution enforce this.
Comments
Post a Comment