/// <summary> /// Creates a graph node. /// </summary> /// <param name="rootObject">The root object.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">@The given type does not match the given object.;rootObject</exception> private IGraphNode CreateNode(object rootObject) { if (rootObject == null) { throw new ArgumentNullException(nameof(rootObject)); } Guid guid = Guid.NewGuid(); // Retrieve results if (guidContainer != null && !rootObject.GetType().IsValueType) { guid = guidContainer.GetOrCreateGuid(rootObject); } var result = (GraphNode)NodeBuilder.Build(rootObject, guid); if (result != null) { // Register reference objects nodesByGuid.Add(result.Guid, result); // Create or update nodes of referenced objects UpdateReferences(result); } return(result); }
/// <summary> /// Creates the model node. /// </summary> /// <param name="rootObject">The root object.</param> /// <param name="type">The type.</param> /// <param name="referencer">The referencer (optional, just here to help having some context when building nodes).</param> /// <returns></returns> /// <exception cref="System.ArgumentException">@The given type does not match the given object.;rootObject</exception> private IModelNode CreateModelNode(object rootObject, Type type, IModelNode referencer) { if (rootObject != null && !type.IsInstanceOfType(rootObject)) { throw new ArgumentException(@"The given type does not match the given object.", "rootObject"); } Guid guid = Guid.NewGuid(); // Retrieve results if (guidContainer != null && rootObject != null && !rootObject.GetType().IsValueType) { guid = guidContainer.GetOrCreateGuid(rootObject); } var result = (ModelNode)NodeBuilder.Build(referencer, rootObject, type, guid); if (result != null) { // Register reference objects modelsByGuid.Add(result.Guid, result); // Create or update model for referenced objects UpdateReferences(result); } return(result); }
/// <summary> /// Gets the node associated to a data object, if it exists, otherwise creates a new node for the object and its member recursively. /// </summary> /// <param name="rootObject">The data object.</param> /// <param name="nodeFactory">The factory to use to create nodes.</param> /// <returns>The <see cref="IGraphNode"/> associated to the given object.</returns> internal IGraphNode GetOrCreateNodeInternal(object rootObject, NodeFactoryDelegate nodeFactory) { if (nodeFactory == null) { throw new ArgumentNullException(nameof(nodeFactory)); } if (rootObject == null) { return(null); } lock (lockObject) { IGraphNode result; if (!rootObject.GetType().IsValueType) { result = GetNodeInternal(rootObject); if (result != null) { return(result); } } var guid = !rootObject.GetType().IsValueType ? guidContainer.GetOrCreateGuid(rootObject) : Guid.NewGuid(); result = NodeBuilder.Build(rootObject, guid, nodeFactory); if (result != null) { // Register reference objects nodesByGuid.Add(result.Guid, result); // Create or update nodes of referenced objects UpdateReferencesInternal(result); } return(result); } }