bu iki kod şeyleri atın:C#: TypeDescriptor.GetAttributes() ve GetType() .GetCustomAttributes Arasındaki Fark Nedir?
instance.GetType()
.GetCustomAttributes(true)
.Where(item => item is ValidationAttribute);
Ve
TypeDescriptor.GetAttributes(instance)
.OfType<ValidationAttribute>();
sınıf gibi görünüyorsa
:RequiredIfOtherPropertyIsNotEmpty
bir
ValidationAttribute
ve
AllowMultiple = true
sahiptir
[RequiredIfOtherPropertyIsNotEmpty("State", "City", ErrorMessage = ErrorDescription.CreateAccount_CityRequiredWithState)]
[RequiredIfOtherPropertyIsNotEmpty("State", "Address1", ErrorMessage = ErrorDescription.CreateAccount_Address1RequiredWithState)]
public class ManagePostModel
{
...
}
.
Birincisi iki özniteliği, ikinci bir tane döndürür.
Buna neden olan fark nedir? the MSDN page on TypeDescriptor.GetAttributes itibaren
da [TypeDescriptor-GetProperties-vs-tipi-GetProperties] Bkz (http://stackoverflow.com/questions/1402239/typedescriptor-getproperties-vs-type-getproperties) – nawfal