C# 把约束变成约束
我有这样一个场景:C# 把约束变成约束,c#,constraints,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 abstract class UblParser<TDto, TUbl> where TUbl : UblBaseDocumentType
where TDto: DtoB
{
public abstract TUbl ParseFrom(TDto dto);
public abstract TDto ParseTo(TUbl document);
}
公共抽象类UblParser,其中TUbl:UblBaseDocumentType
其中TDto:DtoB
{
公共摘要TUbl-ParseFrom(TDto-dto);
公共摘要TDto ParseTo(TUbl文件);
}
如何在另一个约束中使用这样的约束来声明类
public class UblConverter<TParser> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
...
}
公共类UblConverter,其中TParser:UblParser
其中TUbl:ublbase文档类型
其中TDto:DtoB
{
...
}
您必须在类定义中包含所有泛型类型
public class UblConverter<TParser, TDto, TUbl> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
//...
}
公共类UblConverter,其中TParser:UblParser
其中TUbl:ublbase文档类型
其中TDto:DtoB
{
//...
}
您必须在类定义中包含所有泛型类型
public class UblConverter<TParser, TDto, TUbl> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
//...
}
公共类UblConverter,其中TParser:UblParser
其中TUbl:ublbase文档类型
其中TDto:DtoB
{
//...
}
非常好的解决方案,谢谢!很好的解决方案,谢谢!