Wrappers for unrelated types to enable generic constraints in C# -
if have generic type needs contain bool or custom number type called number, bad idea create wrapper type bool , make both wrapper , number inherits same base class? instead of myclass<bool> have myclass<boolwrapper>?
it ensure myclass<righttype>, righttype bool wrapper, number type or common base class. myclass<wrongtype> not allowed. stands between , splitting myclass 2 classes, myclasswithbool , myclasswithnumber. reason due dsl making. might want have method avoid boilerplate code:
public void bind<t>(myclass<t> m) { ... } but allow giving wrong types, want able this:
public void bind<t>(myclass<t> m) t : baseclass { ... } then wouldnt need:
public void bind(myclasswithbool m) { ... } public void bind(myclasswithnumber m) { ... } take care, kerr.
Comments
Post a Comment