/// <summary> /// Creates a <see cref="RelativePath"/> instance from a relative path /// string (e.g. "foo\\bar\\blah.txt") and the corresponding file name (e.g. /// "blah.txt"). <paramref name="relativePath"/> must be end with <paramref /// name="filename"/>. /// </summary> public RelativePath(string relativePath, string filename) { if (relativePath == null) { throw new ArgumentNullException("relativePath"); } if (filename == null) { throw new ArgumentNullException("filename"); } if (PathHelpers.IsAbsolutePath(relativePath)) { throw new ArgumentException("Path must be relative.", "relativePath"); } if (!PathHelpers.IsFileName(filename)) { throw new ArgumentException("Path must be a simple file name + extension.", "filename"); } if (relativePath.Length < filename.Length) { throw new ArgumentException("Relative path must contain file name", "relativePath"); } if (string.Compare(relativePath, relativePath.Length - filename.Length, filename, 0, filename.Length, StringComparison.Ordinal) != 0) { throw new ArgumentException("Relative path must end with file name", "relativePath"); } _relativePath = relativePath; _filename = filename; }
private static string ExtractFileName(string relativePath) { if (relativePath == null) { throw new ArgumentNullException("relativePath"); } if (PathHelpers.IsFileName(relativePath)) { return(relativePath); } return(PathHelpers.GetFileName(relativePath)); }