限制约束

时间:2015-05-27 19:37:14

标签: c# constraints

我有这种情况:

public abstract class UblParser<TDto, TUbl> where TUbl : UblBaseDocumentType
                                            where TDto: DtoB
{
    public abstract TUbl ParseFrom(TDto dto);
    public abstract TDto ParseTo(TUbl document);
}

如何在另一个约束中使用约束声明一个类?

public class UblConverter<TParser> where TParser : UblParser<TDto, TUbl>
                                   where TUbl : UblBaseDocumentType
                                   where TDto : DtoB
{
    ...
}

1 个答案:

答案 0 :(得分:4)

您必须在类定义中包含所有泛型类型。

public class UblConverter<TParser, TDto, TUbl> where TParser : UblParser<TDto, TUbl> 
                                               where TUbl : UblBaseDocumentType 
                                               where TDto : DtoB 
{
    //...
}
相关问题