public class A
{
string name;
public string Name
{
get{return this.name;}
set{this.name=value;}
}
}我通过什么方法在我调用Name属性时可以取到"Name"字符串呢?
{
string name;
public string Name
{
get{return this.name;}
set{this.name=value;}
}
}我通过什么方法在我调用Name属性时可以取到"Name"字符串呢?
foreach(PropertyDescriptor pd in pc)
{
string sv="null";
if(pd.GetValue(xtv)!=null)
sv=pd.GetValue(xtv).ToString();
richTextBox1.AppendText(pd.Name+":"+sv+"\n");
}
//其中xtv是我的自定义控件
这样不仅得到属性名,也可以得到属性值
System.Reflection.PropertyInfo[] pis=xtv.GetType().GetProperties();
richTextBox1.Clear();
foreach(System.Reflection.PropertyInfo pi in pis)
{
string sv="null";
if(pi.GetValue(xtv,(object[])null)!=null)
sv=pi.GetValue(xtv,(object[])null).ToString();
richTextBox1.AppendText(pi.Name+":"+sv+"\n");
}