public static object Merge(this object instance1, object instance2) { if (instance1 != null || instance2 != null) { if (instance1 == null) { return(instance2); } if (instance2 == null) { return(instance1); } IDictionary <string, object> instance1Dictionary = instance1.ToPropertyDictionary(); IDictionary <string, object> instance2Dictionary = instance2.ToPropertyDictionary(); foreach (KeyValuePair <string, object> i in instance2Dictionary.Where(i => !instance1Dictionary.Keys.Contains(i.Key))) { instance1Dictionary.Add(i); } PropertyDef[] newInstanceInfo = instance1Dictionary.Select(i => PropertyDef.New(i.Key, i.Value)).ToArray(); return(AnonymousBuilder.CreateInstance(newInstanceInfo)); } return(null); }
public static object ToParamObject(this ParamDictionary parameters) { return(parameters.Any() ? AnonymousBuilder.CreateInstance(parameters.Values.Select(i => PropertyDef.New(i.Name, i.Value)).ToArray()) : null); }