【发布时间】:2009-12-02 14:37:53
【问题描述】:
拿这两个代码的东西:
instance.GetType()
.GetCustomAttributes(true)
.Where(item => item is ValidationAttribute);
和
TypeDescriptor.GetAttributes(instance)
.OfType<ValidationAttribute>();
如果类看起来像:
[RequiredIfOtherPropertyIsNotEmpty("State", "City", ErrorMessage = ErrorDescription.CreateAccount_CityRequiredWithState)]
[RequiredIfOtherPropertyIsNotEmpty("State", "Address1", ErrorMessage = ErrorDescription.CreateAccount_Address1RequiredWithState)]
public class ManagePostModel
{
...
}
其中RequiredIfOtherPropertyIsNotEmpty 是ValidationAttribute 并具有AllowMultiple = true。
第一个返回两个属性,第二个返回一个。
有什么不同会导致这种情况?
【问题讨论】:
标签: c# attributes typedescriptor