IsDefined() 개인적인 정적인 메소드

private static IsDefined ( char driveLetter ) : bool
driveLetter char
리턴 bool
예제 #1
0
        /// <summary>
        /// Gets a <see cref="SubstitutionDrve"/> for the next available drive letter.
        /// </summary>
        /// <param name="targetPath">The path to the folder to map to a drive letter.</param>
        /// <returns>A <see cref="SubstitutionDrive"/> for the <paramref name="targetPath"/>.</returns>
        internal static SubstituteDrive Next(string targetPath)
        {
            for (var c = 'C'; c <= 'Z'; ++c)
            {
                if (!SubstituteDrive.IsDefined(c))
                {
                    return(new SubstituteDrive(c, targetPath));
                }
            }

            throw new InvalidOperationException("No drive letters are available.");
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubstituteDrive"/> class.
        /// </summary>
        /// <param name="driveLetter">The drive letter to use for the substitution.</param>
        /// <param name="targetPath">The path to the folder to map to a drive letter.</param>
        /// <exception cref="ArgumentException">The <paramref name="driveLetter"/> is already defined.</exception>
        /// <exception cref="Win32Exception">An error occurred when creating a drive subistution.</exception>
        internal SubstituteDrive(char driveLetter, string targetPath)
        {
            Contract.Requires('C' <= driveLetter && 'Z' >= driveLetter);
            Contract.Requires(!string.IsNullOrEmpty(targetPath));

            driveLetter = char.ToUpperInvariant(driveLetter);
            if (SubstituteDrive.IsDefined(driveLetter))
            {
                throw new ArgumentException("The drive letter is already defined.", "driveLetter");
            }

            this.DriveLetter = driveLetter + ":";
            this.TargetPath  = targetPath;

            if (!SubstituteDrive.DefineDosDevice(DefineDosDeviceFlags.None, this.DriveLetter, this.TargetPath))
            {
                // Throw last error.
                throw new Win32Exception();
            }
        }