public DriveInfo(string driveName) { if (Utils.IsNullOrWhiteSpace(driveName)) { throw new ArgumentNullException("driveName"); } if (driveName.Length == 1) { _name += Path.VolumeSeparatorChar; } else { _name = Path.GetPathRoot(driveName, false); } if (Utils.IsNullOrWhiteSpace(_name)) { throw new ArgumentException("Argument must be a drive letter (\"C\"), RootDir (\"C:\\\") or UNC path (\"\\\\server\\share\")"); } // If an exception is thrown, the original drivePath is used. _name = Path.AddTrailingDirectorySeparator(_name, false); // Initiate VolumeInfo() lazyload instance. _volumeInfo = new VolumeInfo(_name, false, true); // Initiate DiskSpaceInfo() lazyload instance. _dsi = new DiskSpaceInfo(_name, null, false, true); }
/// <summary> /// Indicates whether this instance and a specified object are equal. /// </summary> /// <param name="obj">Another object to compare to.</param> /// <returns> /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false. /// </returns> public override bool Equals(object obj) { if (obj == null || !(obj is DiskSpaceInfo)) { return(false); } DiskSpaceInfo other = (DiskSpaceInfo)obj; return(other.FreeBytesAvailable.Equals(FreeBytesAvailable) && other.TotalNumberOfBytes.Equals(TotalNumberOfBytes) && other.TotalNumberOfFreeBytes.Equals(TotalNumberOfFreeBytes)); }
public DriveInfo(string driveName) { if (Utils.IsNullOrWhiteSpace(driveName)) { throw new ArgumentNullException("driveName"); } driveName = driveName.Length == 1 ? driveName + Path.VolumeSeparatorChar : Path.GetPathRoot(driveName, false); if (Utils.IsNullOrWhiteSpace(driveName)) { throw new ArgumentException(Resources.InvalidDriveLetterArgument, "driveName"); } _name = Path.AddTrailingDirectorySeparator(driveName, false); // Initiate VolumeInfo() lazyload instance. _volumeInfo = new VolumeInfo(_name, false, true); // Initiate DiskSpaceInfo() lazyload instance. _dsi = new DiskSpaceInfo(_name, null, false, true); }
public DriveInfo(string driveName) { if (Utils.IsNullOrWhiteSpace(driveName)) throw new ArgumentNullException("driveName"); if (driveName.Length == 1) _name += Path.VolumeSeparatorChar; else _name = Path.GetPathRoot(driveName, false); if (Utils.IsNullOrWhiteSpace(_name)) throw new ArgumentException("Argument must be a drive letter (\"C\"), RootDir (\"C:\\\") or UNC path (\"\\\\server\\share\")"); // If an exception is thrown, the original drivePath is used. _name = Path.AddTrailingDirectorySeparator(_name, false); // Initiate VolumeInfo() lazyload instance. _volumeInfo = new VolumeInfo(_name, false, true); // Initiate DiskSpaceInfo() lazyload instance. _dsi = new DiskSpaceInfo(_name, null, false, true); }