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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -