Added IsPathFullyQualified() method to Path class (#12965)
authorStephanie Niu <niustephanie@users.noreply.github.com>
Fri, 21 Jul 2017 18:11:43 +0000 (11:11 -0700)
committerGitHub <noreply@github.com>
Fri, 21 Jul 2017 18:11:43 +0000 (11:11 -0700)
src/mscorlib/shared/System/IO/Path.cs

index 135bb42..2676f0d 100644 (file)
@@ -166,6 +166,30 @@ namespace System.IO
             return new string(pRandomFileName, 0, RandomFileNameLength);
         }
 
+        /// <summary>
+        /// Returns true if the path is fixed to a specific drive or UNC path. This method does no
+        /// validation of the path (URIs will be returned as relative as a result).
+        /// Returns false if the path specified is relative to the current drive or working directory.
+        /// </summary>
+        /// <remarks>
+        /// Handles paths that use the alternate directory separator.  It is a frequent mistake to
+        /// assume that rooted paths <see cref="Path.IsPathRooted(string)"/> are not relative.  This isn't the case.
+        /// "C:a" is drive relative- meaning that it will be resolved against the current directory
+        /// for C: (rooted, but relative). "C:\a" is rooted and not relative (the current directory
+        /// will not be used to modify the path).
+        /// </remarks>
+        /// <exception cref="ArgumentNullException">
+        /// Thrown if <paramref name="path"/> is null.
+        /// </exception>
+        public static bool IsPathFullyQualified(string path)
+        {
+            if (path == null)
+            {
+                throw new ArgumentNullException(nameof(path));
+            }
+            return !PathInternal.IsPartiallyQualified(path);
+        }
+
         // Tests if a path includes a file extension. The result is
         // true if the characters that follow the last directory
         // separator ('\\' or '/') or volume separator (':') in the path include