/// <summary> /// Removes the path info passes as a parameter from the current root. Only works for two rooted paths with same root. /// Does NOT cover all edge cases, please verify its intended results yourself. /// <example> /// </example> /// </summary> /// <param name = "other"></param> /// <returns></returns> public string RemoveParameterFromRoot(PathInfo other) { Contract.Requires(Root == other.Root, "roots must match to be able to subtract"); Contract.Requires(FolderAndFiles.Length >= other.FolderAndFiles.Length, "The folders and files part of the parameter must be shorter or equal to in length, than that path you wish to subtract from."); if (other.FolderAndFiles == FolderAndFiles) { return(string.Empty); } var startIndex = other.FolderAndFiles.Length; Contract.Assume(startIndex <= FolderAndFiles.Length); var substring = FolderAndFiles.Substring(startIndex); return(substring.TrimStart(Path.GetDirectorySeparatorChars())); }
/// <summary> /// Removes the path info passes as a parameter from the current root. Only works for two rooted paths with same root. /// Does NOT cover all edge cases, please verify its intended results yourself. /// <example> /// /// </example> /// </summary> /// <param name="other"></param> /// <returns></returns> public string RemoveParameterFromRoot(PathInfo other) { if (Root != other.Root) { throw new InvalidOperationException("Roots of this and other don't match."); } if (other.FolderAndFiles.Length > FolderAndFiles.Length) { throw new InvalidOperationException( "The folders and files part of the second parameter must be shorter than that path you wish to subtract from."); } if (other.FolderAndFiles == FolderAndFiles) { return(string.Empty); } return(FolderAndFiles.Substring(other.FolderAndFiles.Length).TrimStart(Path.GetDirectorySeparatorChars())); }