[英]Argument 2: cannot convert from method group to InfoItem
Code: 码:
Dictionary<ValidationType, Func<ValidationModel, InfoItem>> itemValidator = new Dictionary<ValidationType, Func<ValidationModel, InfoItem>>()
{
{ ValidationType.Int32, Validator.ValidateInt }
}
public static class Validator
{
public static ValidationModel ValidateInt(InfoItem item)
{
...
}
}
I am getting the error: 我收到错误消息:
Argument 2: cannot convert from method group to InfoItem
参数2:无法从方法组转换为InfoItem
I have gone through the other errors in the site but I am still at a loss. 我经历了站点中的其他错误,但仍然茫然。 The signature to things looks correct to me which I thought was the error to the other answers on the site!
事物的签名对我来说似乎是正确的,我认为这是该网站上其他答案的错误!
Can someone point me in the right direction? 有人可以指出我正确的方向吗?
public static ValidationModel ValidateInt(InfoItem item)
is a Func<InfoItem, ValidationModel>
, not Func<ValidationModel, InfoItem>
. public static ValidationModel ValidateInt(InfoItem item)
是Func<InfoItem, ValidationModel>
,而不是Func<ValidationModel, InfoItem>
。
Out item is always last in Func
出品总是在
Func
在最后
Since the ValidateInt
method returns a ValidationModel
the value type of your dictionary should be Func<InfoItem, ValidationModel>
. 由于
ValidateInt
方法返回ValidationModel
因此字典的值类型应为Func<InfoItem, ValidationModel>
。 This compiles: 这样编译:
Dictionary<ValidationType, Func<InfoItem, ValidationModel>> itemValidator = new Dictionary<ValidationType, Func<InfoItem, ValidationModel>>()
{
{ ValidationType.Int32, Validator.ValidateInt }
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.