/// <summary>
/// 匿名对象添加自定义属性
/// </summary>
/// <param name="obj"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static dynamic setAttr(dynamic obj, string key, object value)
{
var dict = (obj as IDictionary<string, object>);
if (dict.Keys.Contains(key))
{
dict[key] = value;
}
else
{
dict.Add(key, value);
}
return obj;
}
dynamic obj = new ExpandoObject();
setAttr(obj, key, value);
转:https://blog.csdn.net/u013608482/article/details/88395312