可能重复:
C#如何通过反射获取字符串属性的值?
public class myClass
{
public int a { get; set; }
public int b { get; set; }
public int c { get; set; }
}
public void myMethod(myClass data)
{
Dictionary<string, string> myDict = new Dictionary<string, string>();
Type t = data.GetType();
foreach (PropertyInfo pi in t.GetProperties())
{
myDict[pi.Name] = //...value appropiate sended data.
}
}
带 3 的简单类properties
。我发送这个类的对象。我如何循环获取所有property names
值及其值,例如一个dictionary
?