Bri*_*tel 1 dynamic setattribute propertyinfo silverlight-4.0
我想在任何属性的显示属性中动态地给name属性.
考试:
[Display(Name = "Test")]
public bool Task1
{
get { return this.m_Task1; }
set
{
if (value != this.m_Task1)
{
this.m_Task1 = value;
NotifyPropertyChanged("TaskName");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在该属性中我想动态地给name属性意味着"测试",并且该值将来自数据库.那么如何在生成属性时动态地在显示属性中赋予name属性?任何人都可以帮我找出解决方案吗?
试试这个:
[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";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2839 次 |
| 最近记录: |