Пример #1
0
 public NodeFactoryId RegisterFactory(NodeFactoryDelegate nodeFactory)
 {
     lock (lockObject)
     {
         var id = new NodeFactoryId(Guid.NewGuid());
         nodeFactories.Add(id, nodeFactory);
         return(id);
     }
 }
Пример #2
0
        /// <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="nodeFactoryId">An identifier to the node factory to use to create nodes.</param>
        /// <returns>The <see cref="IGraphNode"/> associated to the given object.</returns>
        public IGraphNode GetOrCreateNode(object rootObject, NodeFactoryId nodeFactoryId = default(NodeFactoryId))
        {
            if (rootObject == null)
            {
                return(null);
            }

            lock (lockObject)
            {
                NodeFactoryDelegate nodeFactory;
                nodeFactories.TryGetValue(nodeFactoryId, out nodeFactory);
                if (nodeFactory == null)
                {
                    nodeFactory = defaultNodeFactory;
                }
                return(GetOrCreateNode(rootObject, nodeFactory));
            }
        }