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
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>
.
Out item is always last in Func
Since the ValidateInt
method returns a ValidationModel
the value type of your dictionary should be Func<InfoItem, ValidationModel>
. This compiles:
Dictionary<ValidationType, Func<InfoItem, ValidationModel>> itemValidator = new Dictionary<ValidationType, Func<InfoItem, ValidationModel>>()
{
{ ValidationType.Int32, Validator.ValidateInt }
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.