简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM