【发布时间】:2015-06-03 17:01:37
【问题描述】:
我有一个现有的 c# 应用程序要修改,并且需要循环一个具有未知属性的对象,并且已经解决了一半的反射问题。
我正在尝试使用属性名称和属性值填充字典。代码如下,我已经描述了我在 ***s 之间需要什么
这是一个 MVC5 项目
private Dictionary<string, string> StoreUserDetails ()
{
var userDetails = new Dictionary<string, string>();
foreach (var userItem in UserItems)
{
var theType = userItem.GetType();
var theProperties = theType.GetProperties();
foreach (var property in theProperties)
{
userDetails.Add(property.Name, ***value of userItem property with this property name***);
}
}
return userDetails;
}
非常感谢您的帮助。
【问题讨论】:
标签: c# reflection properties