System.IO.__Error.GetDisplayablePath C# (CSharp) Méthode

GetDisplayablePath() static private méthode

static private GetDisplayablePath ( String path, bool isInvalidPath ) : String
path String
isInvalidPath bool
Résultat String
        internal static String GetDisplayablePath(String path, bool isInvalidPath)
        {
            if (String.IsNullOrEmpty(path))
                return path;

            // Is it a fully qualified path?
            bool isFullyQualified = false;
            if (path.Length < 2)
                return path;
            if (Path.IsDirectorySeparator(path[0]) && Path.IsDirectorySeparator(path[1]))
                isFullyQualified = true;
            else if (path[1] == Path.VolumeSeparatorChar) {
                isFullyQualified = true;
            }

            if (!isFullyQualified && !isInvalidPath)
                return path;

            bool safeToReturn = false;
            try {
                if (!isInvalidPath) {
                    new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { path }, false, false).Demand();
                    safeToReturn = true;
                }
            }
            catch(ArgumentException) {
                // Needed for Win9x
            }
            catch(NotSupportedException) {
                // Needed for Win9x, which will sometimes return 
                // ERROR_PATH_NOT_FOUND for invalid path names, but also 
                // will leak the current working directory.
            }
            catch(SecurityException) {
            }
            
            if (!safeToReturn) {
                if (Path.IsDirectorySeparator(path[path.Length - 1]))
                    path = Environment.GetResourceString("IO.IO_NoPermissionToDirectoryName");
                else
                    path = Path.GetFileName(path);
            }

            return path;
        }