【发布时间】:2012-05-06 02:28:00
【问题描述】:
可能重复:
C# How can I get the value of a string property via Reflection?
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?
【问题讨论】:
-
我已经看到这个问题回答了很多次了:(stackoverflow.com/questions/987982/…
-
@daryal 然后将问题链接为副本并投票关闭?
-
顺便说一句,.Net 中有一些命名约定
标签: c# loops properties