Is there an easy way to merge C# anonymous objects

If you truly do mean dynamic in the C# 4.0 sense, then you can do something like: static dynamic Combine(dynamic item1, dynamic item2) { var dictionary1 = (IDictionary<string, object>)item1; var dictionary2 = (IDictionary<string, object>)item2; var result = new ExpandoObject(); var d = result as IDictionary<string, object>; //work with the Expando as a Dictionary foreach (var … Read more

Add property to anonymous type after creation

The following extension class would get you what you need. public static class ObjectExtensions { public static IDictionary<string, object> AddProperty(this object obj, string name, object value) { var dictionary = obj.ToDictionary(); dictionary.Add(name, value); return dictionary; } // helper public static IDictionary<string, object> ToDictionary(this object obj) { IDictionary<string, object> result = new Dictionary<string, object>(); PropertyDescriptorCollection properties … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)