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); }
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); }
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); }
public PathBuilder DebasePath(string path, bool caseSensitivePaths) { PathBuilder otherPathBuilder = new PathBuilder(path); return(DebasePath(otherPathBuilder, caseSensitivePaths)); }