Eric Chavez Eric Chavez - 1 year ago 104
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>
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>{


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download