c# - Incorrect number of type parameters in reference class MyClass<F,T> - Generic entity framework -


i've got following generic abstract class:

public abstract class myclass<f, t>     tcurrencyfrom : book     tcurrencyto : book {     public int id { get; set; }     public virtual f first{ get; set; }     public virtual t second { get; set; } } 

and got 3 classes implement class like:

public class implementation1 : myclass<booktype1, booktype2> { }  public class implementation2 : myclass<booktype2, booktype1> { } 

now got "entitytypeconfiguration" looks like:

public class myclassconfiguration<tmyclass> : entitytypeconfiguration<tmyclass> tmyclass: myclass {     public myclassconfiguration()     {         ...     } } 

and try use like:

public class implementation1map : myclassconfiguration<implementation1>  {     public implementation1map ()     {         ...     } } 

but following error:

incorrect number of type parameters in reference class myclass

how can solve problem , make sure have generic approach on entitytypeconfigurations?

unfortunately tricky .net generics.

if myclassconfiguration doesn't care type arguments, might want create non-generic interface:

public interface imyclass {     // members of myclass<,> don't rely on type arguments,     // e.g. id property } 

then make myclass<,> implement imyclass:

// type parameters renamed make type constraints sensible... public abstract class myclass<tcurrencyfrom, tcurrencyto> : imyclass     tcurrencyfrom : book     tcurrencyto : book 

and change type constraint myclassconfiguration:

public class myclassconfiguration<tmyclass> : entitytypeconfiguration<tmyclass>     tmyclass: imyclass 

(obviously you'll want give imyclass more useful name...)

alternatively, make myclassconfiguration generic in 3 type parameters:

public class myclassconfiguration<tmyclass, tcurrencyfrom, tcurrencyto>     : entitytypeconfiguration<tmyclass>     tmyclass: myclass<tcurrencyfrom, tcurrencyto>     tcurrencyfrom : book     tcurrencyto : book  public class implementation1map     : myclassconfiguration<implementation1, booktype1, booktype2>   public class implementation2map     : myclassconfiguration<implementation2, booktype2, booktype1> 

it's ugly, it'll work.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -