我正在尝试设置一些使用System.ComponentModel.DataAnnotations的自定义验证方法。我已经编写了一些用于验证的通用方法。下面是出现问题的地方:
private void SetValidationAttributeErrors<TEntity>(TEntity item, List<string> errors)
{
var result = from prop in TypeDescriptor.GetProperties(item).Cast<PropertyDescriptor>()
from attribute in prop.Attributes.OfType<ValidationAttribute>()
where !attribute.IsValid(prop.GetValue(item))
select attribute.FormatErrorMessage(string.Empty);
}我在'ValidationAttribute‘类型上有一个错误,说找不到它。我有DataAnnotations的using语句。有什么想法吗?
发布于 2013-03-19 06:20:45
不要紧!我想通了。显然,using语句是不够的。我还必须将项目引用添加到包中。
https://stackoverflow.com/questions/15487464
复制相似问题