我有一个接口,用于将实体对象映射到域对象

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


实施

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


我如何编写接口以允许我编写这样的实现

 public class MyEntity : IDataEntity<MyDomainObj>{
 }


谢谢!

最佳答案

你不能您将不得不写出完整的通用参数列表。

关于c# - 使用C#泛型的助手,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40850916/

10-09 00:20