C#转换列表<;对象>;列出<;动态>;并添加属性
在c#中,我想将列表转换为列表 并向对象动态添加新属性C#转换列表<;对象>;列出<;动态>;并添加属性,c#,.net,c#-4.0,expandoobject,C#,.net,C# 4.0,Expandoobject,在c#中,我想将列表转换为列表 并向对象动态添加新属性 List<Customer> customerList; // has list of customer object List<Properties> properties; // has { string:propertyname and string:value} 我会要求通过API调用从我的UI访问此列表,并以JSON格式返回数据,我不会这样做。我会将我的列表保留为Customer的列表,并且我会扩展我的C
List<Customer> customerList; // has list of customer object
List<Properties> properties; // has { string:propertyname and string:value}
我会要求通过API调用从我的UI访问此列表,并以JSON格式返回数据,我不会这样做。我会将我的列表保留为
Customer
的列表,并且我会扩展我的Customer
类,以支持访问通过
专用词典;
公开这个[字符串i]
{
获取{返回InnerDictionary[i];}
集合{innerdiodictionary[i]=value;}
}
我需要通过API调用从我的UI访问此列表,并以JSON格式返回数据,因此我希望它采用对象格式。我可以添加public dynamic custom=new ExpandoObject();到客户并迭代客户,var cust=customers[i];var exp=item.custom作为IDictionary;exp[cust.propertyName]=cust.value??字符串。空;但是否有一种方法可以将属性添加到客户,而不是添加到客户内部的属性。
for(Customer c in customerList)
{
for(Property prop in properties)
{
c[prop.propertyName]=prop.value; // similar to javascript
}
}
private Dictionary<string,Something>;
public Something this[string i]
{
get { return InnerDictionary[i]; }
set { InnerDictionary[i] = value; }
}