简体   繁体   English

使用C#Generics的助手

[英]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. 您必须写出完整的通用参数列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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