问题描述
我做了一个自定义的枚举验证器,以检查IEnumerable中的int是否属于Enum
public class CustomEnumValidator<T> : AbstractValidator<int>
where T : struct,IConvertible
{
public CustomEnumValidator(int value)
{
if (Enum.IsDefined(typeof(T),value))
{
throw new ArgumentException("Value must be part of enum");
}
}
}
我不确定这是否行得通,因为我在将int值传递给自定义验证程序时遇到问题
RuleForEach(x => x.Values) //Values is IEnumerable<int>
.SetValidator(new CustomEnumValidator<CustomEnumValues>(x))//this line is throwing error
.When(x => x.Values.Any());
那么如何将每个int值传递给CustomEnumValidator,验证器是否正确?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)