I want to give name property dynamically in the display attributes for any property.
for exam:
[Display(Name = "Test")]
public bool Task1
{
get { return this.m_Task1; }
set
{
if (value != this.m_Task1)
{
this.m_Task1 = value;
NotifyPropertyChanged("TaskName");
}
}
开发者_开发技巧 }
in that property i want to give the name property dynamically means "Test" and that values will comes from the database. So how can i give the name property dynamically in display attributes while generating the property? Can any one help me to find out the solution?
Try this:
[Display(Name = "Tu edad")]
public int Edad
{
get { bla, bla...; }
set { bla, bla...; }
}
public void ChangeEdad()
{
var TheProperty =
this.GetType().GetProperties().Where(x => x.Name == "Edad").FirstOrDefault();
object TheAttribute =
TheProperty.GetCustomAttributes(typeof(DisplayAttribute), false)[0];
DisplayAttribute DA = TheAttribute as DisplayAttribute;
DA.Name = "Your Age";
}
精彩评论