Exemple #1
0
        /// <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;
        }
Exemple #2
0
 /// <summary>
 /// Creates a <see cref="RelativePath"/> instance from a relative
 /// path string (e.g. "foo\\bar\\blah.txt").
 /// </summary>
 public RelativePath(string relativePath)
 {
     Invariants.CheckArgumentNotNull(relativePath, nameof(relativePath));
     Invariants.CheckArgument(!PathHelpers.IsAbsolutePath(relativePath), nameof(relativePath), "Path must be relative.");
     // Empty string is the same as the empty relative path
     _relativePath = relativePath == "" ? null : relativePath;
 }
Exemple #3
0
 public FullPath(string path)
 {
     if (!PathHelpers.IsAbsolutePath(path))
     {
         ThrowInvalidPath(path);
     }
     _path = path;
 }
Exemple #4
0
 public static bool IsValid(string path)
 {
     return(PathHelpers.IsAbsolutePath(path));
 }