Beispiel #1
0
        public PathBuilder CombineWith(PathBuilder path)
        {
            Contract.Requires(path != null);

            if (!path.IsRelative)
            {
                throw new ArgumentException("Cannot combine a path with an absolute path", nameof(path));
            }

            PathBuilder combined = new PathBuilder(this);

            combined.pathComponents.AddRange(path.pathComponents);
            return(combined);
        }
Beispiel #2
0
        public PathBuilder DebasePath(PathBuilder path, bool caseSensitivePaths)
        {
            Contract.Requires(path != null);

            if (!IsBasePathOf(path, caseSensitivePaths))
            {
                return(null);
            }

            PathBuilder debasedPath = new PathBuilder();

            for (int i = PathDepth; i < path.PathDepth; i++)
            {
                debasedPath.pathComponents.Add(path.pathComponents[i]);
            }

            return(debasedPath);
        }
Beispiel #3
0
        public bool IsBasePathOf(PathBuilder other, bool caseSensitivePaths)
        {
            Contract.Requires(other != null);

            if (IsRelative != other.IsRelative)
            {
                return(false);
            }

            if (IsUncPath != other.IsUncPath)
            {
                return(false);
            }

            if (PathDepth > other.PathDepth)
            {
                return(false);
            }

            StringComparison stringComparison = caseSensitivePaths ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            if (!PathRoot.Equals(other.PathRoot, stringComparison))
            {
                return(false);
            }

            for (int i = 0; i < pathComponents.Count; i++)
            {
                string thisPathComponent  = pathComponents[i];
                string otherPathComponent = other.pathComponents[i];
                if (!thisPathComponent.Equals(otherPathComponent, stringComparison))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
        public PathBuilder DebasePath(string path, bool caseSensitivePaths)
        {
            PathBuilder otherPathBuilder = new PathBuilder(path);

            return(DebasePath(otherPathBuilder, caseSensitivePaths));
        }