Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#转换列表<;对象>;列出<;动态>;并添加属性_C#_.net_C# 4.0_Expandoobject - Fatal编程技术网

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

在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; }
}