internal static object[] ClassifyObjects(object[] args) { List <object> objIndex = new List <object>(); object objName = null; foreach (var arg in args) { if (arg != null) { if (Formatter.IsAnonymousType(arg.GetType())) { if (objName == null) { objName = arg; } else { objName = TypeMerger.MergeTypes(objName, arg); } } else { objIndex.Add(arg); } } } if (objName != null) { objIndex.Add(objName); } return(objIndex.ToArray()); }
public void MergeObject_MergesTwoObjects_IntoANewObject() { var object1 = new { Id = 1, Name = "Object1", DateCreated = new DateTime(2001, 1, 1) }; var object2 = new { Id = 3, Description = "Object2 is richer", Money = 12345.0M }; var mergedObject = TypeMerger.MergeTypes(object1, object2); var dictionary = mergedObject.ToDictionary(); Assert.Equal("Object1", dictionary["Name"]); Assert.Equal("Object2 is richer", dictionary["Description"]); Assert.Equal(12345.0M, dictionary["Money"]); Assert.Equal(new DateTime(2001, 1, 1), dictionary["DateCreated"]); Assert.Equal(1, dictionary["Id"]); }
public object MergeTypes(object values1, object values2) { return(TypeMerger.MergeTypes(values1, values2, this)); }
/// <summary>.</summary> public static object MergeTypes(object values1, object values2, TypeMergerPolicy policy) { TypeMerger.kTypeMergerPolicy = policy; return(TypeMerger.MergeTypes(values1, values2)); }