[英]C# how to use generic constraint with interface
Can anyone help me what am i doing wrong with the following c# code? 谁能帮我使用以下C#代码做错什么? I am basically trying to add the constraint to ICommandHandler.
我基本上是想将约束添加到ICommandHandler。
public interface ICommand<T> where T : BaseDto{ }
public abstract class BaseCommand<T> : ICommand<T> where T : BaseDto { }
public class CreateAlertCommand : BaseCommand<AlertDto>{}
public interface ICommandHandler<TCommand> where TCommand : ICommand{}
I am getting error when defining ICommandHandler. 定义ICommandHandler时出现错误。 It says
'Using the generic type ICommand<T> requires 1 type argument'
它说:
'Using the generic type ICommand<T> requires 1 type argument'
public interface ICommandHandler<TCommand>
where TCommand : ICommand
{
}
Should be: 应该:
public interface ICommandHandler<TCommand,TDto>
where TCommand : ICommand<TDto>
where TDto : BaseDto
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.