public void SetObjectData(ref object obj, IObjectGraphNode node) { Type objType = obj.GetType(); Type elemType = objType.GetGenericArguments()[0]; IGraphNode comparerData = node["comparer"]; if (comparerData != null) { Type comparerType = typeof(IEqualityComparer <>).MakeGenericType(elemType); var comparerObject = comparerData.RebuildObject(comparerType); var f = objType.GetField("m_comparer", BindingFlags.NonPublic | BindingFlags.Instance); f.SetValue(obj, comparerObject); } ISequenceGraphNode elements = node["elements"] as ISequenceGraphNode; if (elements != null) { var m = objType.GetMethod("UnionWith"); var a = Array.CreateInstance(elemType, elements.Length); elements.Select(e => e.RebuildObject(elemType)).ToArray().CopyTo(a, 0); m.Invoke(obj, new object[] { a }); } }
public void SetObjectData(ref object obj, IObjectGraphNode node) { Type objType = obj.GetType(); Type elemType = TypeTools.GetGenericArguments(objType)[0]; IGraphNode comparerData = node["comparer"]; if (comparerData != null) { Type comparerType = typeof(IEqualityComparer <>).MakeGenericType(elemType); var comparer = comparerData.RebuildObject(comparerType); objType.GetConstructor(false, comparerType).Invoke(obj, new[] { comparer }); } else { objType.GetConstructor(false).Invoke(obj, null); } ISequenceGraphNode elements = node["elements"] as ISequenceGraphNode; if (elements != null) { var m = TypeTools.GetRuntimeMethod(objType, "UnionWith"); var a = Array.CreateInstance(elemType, elements.Length); elements.Select(e => e.RebuildObject(elemType)).ToArray().CopyTo(a, 0); m.Invoke(obj, new object[] { a }); } }