我的目标是获取类属性及其值。如何获取可变属性值?
举例来说,如果我有一个属性“可绑定”,以检查是否属性是可绑定:
public class Bindable : Attribute
{
public bool IsBindable { get; set; }
}
而且我有一个Person类:
public class Person
{
[Bindable(IsBindable = true)]
public string FirstName { get; set; }
[Bindable(IsBindable = false)]
public string LastName { get; set; }
}
我怎样才能名字的和姓氏的'Bindable'属性值?
public void Bind()
{
Person p = new Person();
if (FirstName property is Bindable)
p.FirstName = "";
if (LastName property is Bindable)
p.LastName = "";
}
谢谢。
有一个不错的[属性教程](http://msdn.microsoft.com/en-us/library/aa288454.aspx)覆盖这个MSDN上。 –
@克里斯:谢谢,将编辑。 –