//Get PropertyDescriptor object for the given property name
var propDesc = TypeDescriptor.GetProperties(typeof(T))[propName];
//Get FillAttributes methodinfo delegate
var methodInfo = propDesc.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic)
.FirstOrDefault(m => m.IsFamily || m.IsPublic && m.Name == "FillAttributes");
//Create Validation attribute
var attribute = new RequiredAttribute();
var attributes= new ValidationAttribute[]{attribute};
//Invoke FillAttribute method
methodInfo.Invoke(propDesc, new object[] { attributes });
पर किसी प्रॉपर्टी में कोई विशेषता जोड़ने के लिए हाय मैं उपरोक्त कोड का उपयोग कर रनटाइम पर सत्यापन विशेषता जोड़ने की कोशिश कर रहा हूं। हालांकि मैं नीचे अपवाद हो रही है:रनटाइम
संग्रह एक निश्चित आकार
संभव डुप्लिकेट विशेषताओं में गतिशील रूप से जोड़ा जा सकता है सी #?] (Http://stackoverflow.com/questions/129285/can-attributes-be-added- गतिशील-in-c) –