I want to iterate through my class properties (may be metaData) to determine which validation ([Required]
and [MaxLength]
for example) or other attributes have been applied to those properties.
// model is my class
var modelTypeTemp = model.GetType();
var metaData = ModelMetadataProviders.Current.GetMetadataForType(null, modelTypeTemp);
var behaviourAttributes= metaData.GetBehaviourDataAttributes();
var temp2=modelTypeTemp.GetCustomAttributesData();
object[] attrs = modelTypeTemp.GetCustomAttributes(true);
foreach (Attribute attr in attrs)
{
var temp = attr;
}
I have tried different combinations of the code above (Custom and Behaviour attributes) but still can't see the applied attributes.
I want to do this for debugging purposes.