Eric Chavez Eric Chavez - 9 days ago 5
C# Question

Assistant Using C# Generics

I have an interface which I use to map Entities Objects to Domain Objects

public interface IDataEntity<in T1, out T2> where T1 : new() where T2 : new()
{
T2 Map(T1 obj);
}


To implement

public class MyEntityObj : IDataEntity<MyEntityObj, MyDomainObj>
{
//props
public MyDomainObj Map(MyEntityObj obj){
// mapping here
return new MyDomainObj();
}
}


How could I write the interface to allow me to write the implementation like this

public class MyEntity : IDataEntity<MyDomainObj>{
}


Thanks!

Answer

You can't. You will have to write out the full generic argument list.