以下两个代码:
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
.
第一个返回两个属性,第二个返回一个。
会导致这种情况的区别是什么?