有约束为约束
Having constraints into 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);
}
我如何声明一个 class 在像这样的另一个约束中使用一个约束?
public class UblConverter<TParser> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
...
}
您必须在 class 定义中包含所有通用类型。
public class UblConverter<TParser, TDto, TUbl> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
//...
}
我有这个场景:
public abstract class UblParser<TDto, TUbl> where TUbl : UblBaseDocumentType
where TDto: DtoB
{
public abstract TUbl ParseFrom(TDto dto);
public abstract TDto ParseTo(TUbl document);
}
我如何声明一个 class 在像这样的另一个约束中使用一个约束?
public class UblConverter<TParser> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
...
}
您必须在 class 定义中包含所有通用类型。
public class UblConverter<TParser, TDto, TUbl> where TParser : UblParser<TDto, TUbl>
where TUbl : UblBaseDocumentType
where TDto : DtoB
{
//...
}