c# - Generics and Factories -


I am new to generic and trying to figure out which class I can return the example See sample code from a factory below whose base is normal. These issues are highlighted in the Factory Class:

  Public Essentials MyGenericBaseClass & lt; T & gt; {Public string fu () {...}} Public Sealed Class MyDerivedIntClass: MyGenericBaseClass & lt; Int & gt; {} Public Sealed Class MyDerivedStringClass: MyGenericBaseClass & lt; String & gt; {} Public stable class MyClassFactory {public stable MyGenericBaseClass & lt; T & gt; CreateMyClass & lt; T & gt; () {// ************************************************************************ ************************************************************************************************************************************ **** ***** if (typef (t) == typef (int)) Return to the new meridiement class (); } If (typef (t) == typewriter (string) {Return the new mildeword string cloud (); } // ************************************************************************************************************************************ **************************************** How do I see it?  

thanks a tonne

ohji

my generic In most of the classes, I put a non-normal interface. Actually, I will apply something like this:

  Public interface INonGenericInterface {string Foo (); } Public Essentials MyGenericBaseClass & lt; T & gt; {INNGenericInterface {public string foo} {...}} Public stable class MyClassFactory {public static INonGenericInterface CreateMyDerivedIntClass () {New MyDerivedIntClass (); } Public stable INonGenericInterface CreateMyDerivedStringClass () {New MyDerivedStringClass (); }}  

In this way, you can clearly say what type of type can be made and still can destroy the collar with a solid type.

Of course, you do not necessarily need a non-normal interface for this scenario, but in fact, you will need the most for this.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -