Ejemplo n.º 1
0
        /// <summary>
        ///     Determine whether the <see cref="XSPath"/> has the specified path as its direct ancestor.
        /// </summary>
        /// <param name="parentPath">
        ///     The other <see cref="XSPath"/>.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the other <see cref="XSPath"/>'s trailing segments are the same as the <see cref="XSPath"/>'s ancestor segments.
        /// </returns>
        public bool IsChildOf(XSPath parentPath)
        {
            if (parentPath == null)
            {
                throw new ArgumentNullException(nameof(parentPath));
            }

            if (IsAbsolute && !parentPath.IsAbsolute)
            {
                return(false); // Logical short-circuit: absolute path cannot be a child of another path.
            }
            // Special case: any relative path is considered a child of the root.
            if (IsRelative && parentPath == Root)
            {
                return(true);
            }

            return(_ancestorSegments.EndsWith(parentPath._segments));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Determine whether the <see cref="XSPath"/> has ends with the the specified path.
        /// </summary>
        /// <param name="ancestorPath">
        ///     The other <see cref="XSPath"/>.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the other <see cref="XSPath"/>'s trailing segments are the same as the <see cref="XSPath"/>'s segments.
        /// </returns>
        public bool EndsWith(XSPath ancestorPath)
        {
            if (ancestorPath == null)
            {
                throw new ArgumentNullException(nameof(ancestorPath));
            }

            if (ancestorPath.IsAbsolute)
            {
                return(StartsWith(ancestorPath));
            }

            if (_ancestorSegments.Count == 0 && Leaf == ancestorPath.Leaf)
            {
                return(true);
            }

            return(_segments.EndsWith(ancestorPath._segments));
        }