Exemple #1
0
        /// <summary>
        /// Visits the <see cref="ReferenceEnumerable"/> contained in the given node, if any.
        /// </summary>
        /// <param name="node">The node being visited.</param>
        /// <param name="currentPath">The path of the node being visited.</param>
        public virtual void VisitEnumerableTargets(IGraphNode node, GraphNodePath currentPath)
        {
            var enumerableReference = node.Content.Reference as ReferenceEnumerable;

            if (enumerableReference != null)
            {
                foreach (var reference in enumerableReference.Where(x => x.TargetNode != null))
                {
                    var targetPath = currentPath.PushIndex(reference.Index);
                    VisitReference(node, reference, targetPath);
                }
            }
        }
Exemple #2
0
        public static GraphNodePath From(IGraphNode root, MemberPath memberPath, out Index index)
        {
            var result = new GraphNodePath(root);

            index = Index.Empty;
            var memberPathItems = memberPath.Decompose();

            for (int i = 0; i < memberPathItems.Count; i++)
            {
                var  memberPathItem = memberPathItems[i];
                bool lastItem       = i == memberPathItems.Count - 1;
                if (memberPathItem.MemberDescriptor != null)
                {
                    result = result.PushMember(memberPathItem.MemberDescriptor.Name);
                }
                else if (memberPathItem.GetIndex() != null)
                {
                    var localIndex = new Index(memberPathItem.GetIndex());

                    if (lastItem)
                    {
                        // If last item, we directly return the index rather than add it to the path
                        index = localIndex;
                    }
                    else
                    {
                        result = result.PushIndex(localIndex);
                    }
                }

                // Don't apply Target on last item
                if (!lastItem)
                {
                    // If this is a reference, add a target element to the path
                    var node            = result.GetNode();
                    var objectReference = node.Content.Reference as ObjectReference;
                    if (objectReference?.TargetNode != null)
                    {
                        result = result.PushTarget();
                    }
                }
            }

            return(result);
        }
 /// <summary>
 /// Visits the <see cref="ReferenceEnumerable"/> contained in the given node, if any.
 /// </summary>
 /// <param name="node">The node being visited.</param>
 /// <param name="currentPath">The path of the node being visited.</param>
 public virtual void VisitEnumerableTargets(IGraphNode node, GraphNodePath currentPath)
 {
     var enumerableReference = node.Content.Reference as ReferenceEnumerable;
     if (enumerableReference != null)
     {
         foreach (var reference in enumerableReference.Where(x => x.TargetNode != null))
         {
             var targetPath = currentPath.PushIndex(reference.Index);
             VisitReference(node, reference, targetPath);
         }
     }
 }
        /// <summary>
        /// Retrieves the path of the target node if the given source node content holds a reference or a sequence of references, or the given source node path otherwise.
        /// </summary>
        /// <param name="sourceNode">The source node for which to retrieve the target node.</param>
        /// <param name="index">The index of the target node to retrieve, if the source node contains a sequence of references. <see cref="Index.Empty"/> otherwise.</param>
        /// <param name="sourceNodePath">The path to the given <paramref name="sourceNode"/>.</param>
        /// <returns>The path to the corresponding target node if available, or the path to source node itself if it does not contain any reference or if its content should not process references.</returns>
        /// <remarks>This method can return null if the target node is null.</remarks>
        protected static GraphNodePath GetTargetNodePath(IGraphNode sourceNode, Index index, GraphNodePath sourceNodePath)
        {
            if (sourceNode == null) throw new ArgumentNullException(nameof(sourceNode));
            if (sourceNodePath == null) throw new ArgumentNullException(nameof(sourceNodePath));

            var objectReference = sourceNode.Content.Reference as ObjectReference;
            if (objectReference != null)
            {
                return sourceNodePath.PushTarget();
            }

            var referenceEnumerable = sourceNode.Content.Reference as ReferenceEnumerable;
            if (referenceEnumerable != null && !index.IsEmpty)
            {
                return sourceNodePath.PushIndex(index);
            }

            return sourceNodePath.Clone();
        }