diff options
Diffstat (limited to 'src/mscorlib/src/System/IO')
20 files changed, 234 insertions, 234 deletions
diff --git a/src/mscorlib/src/System/IO/BinaryReader.cs b/src/mscorlib/src/System/IO/BinaryReader.cs index 2f81b0072c..cebba6ea98 100644 --- a/src/mscorlib/src/System/IO/BinaryReader.cs +++ b/src/mscorlib/src/System/IO/BinaryReader.cs @@ -60,7 +60,7 @@ namespace System.IO throw new ArgumentNullException(nameof(encoding)); } if (!input.CanRead) - throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); + throw new ArgumentException(SR.Argument_StreamNotReadable); Contract.EndContractBlock(); m_stream = input; m_decoder = encoding.GetDecoder(); @@ -264,7 +264,7 @@ namespace System.IO catch (ArgumentException e) { // ReadDecimal cannot leak out ArgumentException - throw new IOException(Environment.GetResourceString("Arg_DecBitCtor"), e); + throw new IOException(SR.Arg_DecBitCtor, e); } } @@ -285,7 +285,7 @@ namespace System.IO stringLength = Read7BitEncodedInt(); if (stringLength < 0) { - throw new IOException(Environment.GetResourceString("IO.IO_InvalidStringLen_Len", stringLength)); + throw new IOException(SR.Format(SR.IO_InvalidStringLen_Len, stringLength)); } if (stringLength == 0) @@ -332,19 +332,19 @@ namespace System.IO { if (buffer == null) { - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); } if (index < 0) { - throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); } if (buffer.Length - index < count) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); } Contract.Ensures(Contract.Result<int>() >= 0); Contract.Ensures(Contract.Result<int>() <= count); @@ -524,7 +524,7 @@ namespace System.IO { if (count < 0) { - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.Ensures(Contract.Result<char[]>() != null); Contract.Ensures(Contract.Result<char[]>().Length <= count); @@ -555,13 +555,13 @@ namespace System.IO public virtual int Read(byte[] buffer, int index, int count) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.Ensures(Contract.Result<int>() >= 0); Contract.Ensures(Contract.Result<int>() <= count); Contract.EndContractBlock(); @@ -572,7 +572,7 @@ namespace System.IO public virtual byte[] ReadBytes(int count) { - if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Contract.Result<byte[]>() != null); Contract.Ensures(Contract.Result<byte[]>().Length <= Contract.OldValue(count)); Contract.EndContractBlock(); @@ -610,7 +610,7 @@ namespace System.IO { if (m_buffer != null && (numBytes < 0 || numBytes > m_buffer.Length)) { - throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_BinaryReaderFillBuffer")); + throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_BinaryReaderFillBuffer); } int bytesRead = 0; int n = 0; @@ -652,7 +652,7 @@ namespace System.IO // Check for a corrupted stream. Read a max of 5 bytes. // In a future version, add a DataFormatException. if (shift == 5 * 7) // 5 bytes max per Int32, shift += 7 - throw new FormatException(Environment.GetResourceString("Format_Bad7BitInt32")); + throw new FormatException(SR.Format_Bad7BitInt32); // ReadByte handles end of stream cases for us. b = ReadByte(); diff --git a/src/mscorlib/src/System/IO/BinaryWriter.cs b/src/mscorlib/src/System/IO/BinaryWriter.cs index ffa5f6edaf..3d9839f46e 100644 --- a/src/mscorlib/src/System/IO/BinaryWriter.cs +++ b/src/mscorlib/src/System/IO/BinaryWriter.cs @@ -71,7 +71,7 @@ namespace System.IO if (encoding == null) throw new ArgumentNullException(nameof(encoding)); if (!output.CanWrite) - throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable")); + throw new ArgumentException(SR.Argument_StreamNotWritable); Contract.EndContractBlock(); OutStream = output; @@ -188,7 +188,7 @@ namespace System.IO public unsafe virtual void Write(char ch) { if (Char.IsSurrogate(ch)) - throw new ArgumentException(Environment.GetResourceString("Arg_SurrogatesNotAllowedAsSingleChar")); + throw new ArgumentException(SR.Arg_SurrogatesNotAllowedAsSingleChar); Contract.EndContractBlock(); Debug.Assert(_encoding.GetMaxByteCount(1) <= 16, "_encoding.GetMaxByteCount(1) <= 16)"); diff --git a/src/mscorlib/src/System/IO/Directory.cs b/src/mscorlib/src/System/IO/Directory.cs index c8c0142363..c472cdf374 100644 --- a/src/mscorlib/src/System/IO/Directory.cs +++ b/src/mscorlib/src/System/IO/Directory.cs @@ -55,7 +55,7 @@ namespace System.IO if (searchPattern == null) throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), SR.ArgumentOutOfRange_Enum); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -135,9 +135,9 @@ namespace System.IO if (path == null) throw new ArgumentNullException(nameof(path)); if (path.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty")); + throw new ArgumentException(SR.Argument_PathEmpty); if (path.Length >= Path.MaxPath) - throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); + throw new PathTooLongException(SR.IO_PathTooLong); String fulldestDirName = Path.GetFullPath(path); diff --git a/src/mscorlib/src/System/IO/DirectoryNotFoundException.cs b/src/mscorlib/src/System/IO/DirectoryNotFoundException.cs index 31b1eba6d5..1cc6cc4e58 100644 --- a/src/mscorlib/src/System/IO/DirectoryNotFoundException.cs +++ b/src/mscorlib/src/System/IO/DirectoryNotFoundException.cs @@ -28,7 +28,7 @@ namespace System.IO public class DirectoryNotFoundException : IOException { public DirectoryNotFoundException() - : base(Environment.GetResourceString("Arg_DirectoryNotFoundException")) + : base(SR.Arg_DirectoryNotFoundException) { SetErrorCode(__HResults.COR_E_DIRECTORYNOTFOUND); } diff --git a/src/mscorlib/src/System/IO/DriveNotFoundException.cs b/src/mscorlib/src/System/IO/DriveNotFoundException.cs index 6c5bb765b2..c48d7ac359 100644 --- a/src/mscorlib/src/System/IO/DriveNotFoundException.cs +++ b/src/mscorlib/src/System/IO/DriveNotFoundException.cs @@ -21,7 +21,7 @@ namespace System.IO internal class DriveNotFoundException : IOException { public DriveNotFoundException() - : base(Environment.GetResourceString("Arg_DriveNotFoundException")) + : base(SR.Arg_DriveNotFoundException) { SetErrorCode(__HResults.COR_E_DIRECTORYNOTFOUND); } diff --git a/src/mscorlib/src/System/IO/EndOfStreamException.cs b/src/mscorlib/src/System/IO/EndOfStreamException.cs index 3b73dff7fb..1eb1664e7f 100644 --- a/src/mscorlib/src/System/IO/EndOfStreamException.cs +++ b/src/mscorlib/src/System/IO/EndOfStreamException.cs @@ -22,7 +22,7 @@ namespace System.IO public class EndOfStreamException : IOException { public EndOfStreamException() - : base(Environment.GetResourceString("Arg_EndOfStreamException")) + : base(SR.Arg_EndOfStreamException) { SetErrorCode(__HResults.COR_E_ENDOFSTREAM); } diff --git a/src/mscorlib/src/System/IO/File.cs b/src/mscorlib/src/System/IO/File.cs index 5c6b5fcf01..4aba1488ec 100644 --- a/src/mscorlib/src/System/IO/File.cs +++ b/src/mscorlib/src/System/IO/File.cs @@ -93,7 +93,7 @@ namespace System.IO int index = 0; long fileLength = fs.Length; if (fileLength > Int32.MaxValue) - throw new IOException(Environment.GetResourceString("IO.IO_FileTooLong2GB")); + throw new IOException(SR.IO_FileTooLong2GB); int count = (int)fileLength; bytes = new byte[count]; while (count > 0) @@ -114,7 +114,7 @@ namespace System.IO if (path == null) throw new ArgumentNullException(nameof(path)); if (path.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); + throw new ArgumentException(SR.Argument_EmptyPath); Contract.EndContractBlock(); return InternalReadAllLines(path, Encoding.UTF8); diff --git a/src/mscorlib/src/System/IO/FileLoadException.cs b/src/mscorlib/src/System/IO/FileLoadException.cs index e55fdbb118..6c5b26871b 100644 --- a/src/mscorlib/src/System/IO/FileLoadException.cs +++ b/src/mscorlib/src/System/IO/FileLoadException.cs @@ -32,7 +32,7 @@ namespace System.IO private String _fusionLog; // fusion log (when applicable) public FileLoadException() - : base(Environment.GetResourceString("IO.FileLoad")) + : base(SR.IO_FileLoad) { SetErrorCode(__HResults.COR_E_FILELOAD); } @@ -87,7 +87,7 @@ namespace System.IO String s = GetType().FullName + ": " + Message; if (_fileName != null && _fileName.Length != 0) - s += Environment.NewLine + Environment.GetResourceString("IO.FileName_Name", _fileName); + s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, _fileName); if (InnerException != null) s = s + " ---> " + InnerException.ToString(); diff --git a/src/mscorlib/src/System/IO/FileNotFoundException.cs b/src/mscorlib/src/System/IO/FileNotFoundException.cs index e25667e302..987aaa9150 100644 --- a/src/mscorlib/src/System/IO/FileNotFoundException.cs +++ b/src/mscorlib/src/System/IO/FileNotFoundException.cs @@ -29,7 +29,7 @@ namespace System.IO private String _fusionLog; // fusion log (when applicable) public FileNotFoundException() - : base(Environment.GetResourceString("IO.FileNotFound")) + : base(SR.IO_FileNotFound) { SetErrorCode(__HResults.COR_E_FILENOTFOUND); } @@ -74,7 +74,7 @@ namespace System.IO { if ((_fileName == null) && (HResult == System.__HResults.COR_E_EXCEPTION)) - _message = Environment.GetResourceString("IO.FileNotFound"); + _message = SR.IO_FileNotFound; else if (_fileName != null) _message = FileLoadException.FormatFileLoadExceptionMessage(_fileName, HResult); @@ -91,7 +91,7 @@ namespace System.IO String s = GetType().FullName + ": " + Message; if (_fileName != null && _fileName.Length != 0) - s += Environment.NewLine + Environment.GetResourceString("IO.FileName_Name", _fileName); + s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, _fileName); if (InnerException != null) s = s + " ---> " + InnerException.ToString(); diff --git a/src/mscorlib/src/System/IO/IOException.cs b/src/mscorlib/src/System/IO/IOException.cs index c2603e6fab..a91d891d8f 100644 --- a/src/mscorlib/src/System/IO/IOException.cs +++ b/src/mscorlib/src/System/IO/IOException.cs @@ -33,7 +33,7 @@ namespace System.IO private String _maybeFullPath; // For debuggers on partial trust code public IOException() - : base(Environment.GetResourceString("Arg_IOException")) + : base(SR.Arg_IOException) { SetErrorCode(__HResults.COR_E_IO); } diff --git a/src/mscorlib/src/System/IO/MemoryStream.cs b/src/mscorlib/src/System/IO/MemoryStream.cs index 920157723e..80b3af0aee 100644 --- a/src/mscorlib/src/System/IO/MemoryStream.cs +++ b/src/mscorlib/src/System/IO/MemoryStream.cs @@ -64,7 +64,7 @@ namespace System.IO { if (capacity < 0) { - throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); + throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NegativeCapacity); } Contract.EndContractBlock(); @@ -84,7 +84,7 @@ namespace System.IO public MemoryStream(byte[] buffer, bool writable) { - if (buffer == null) throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + if (buffer == null) throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); Contract.EndContractBlock(); _buffer = buffer; _length = _capacity = buffer.Length; @@ -107,13 +107,13 @@ namespace System.IO public MemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); _buffer = buffer; @@ -173,7 +173,7 @@ namespace System.IO { // Check for overflow if (value < 0) - throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong")); + throw new IOException(SR.IO_StreamTooLong); if (value > _capacity) { int newCapacity = value; @@ -218,7 +218,7 @@ namespace System.IO public virtual byte[] GetBuffer() { if (!_exposable) - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_MemStreamBuffer")); + throw new UnauthorizedAccessException(SR.UnauthorizedAccess_MemStreamBuffer); return _buffer; } @@ -302,7 +302,7 @@ namespace System.IO { // Only update the capacity if the MS is expandable and the value is different than the current capacity. // Special behavior if the MS isn't expandable: we don't throw if value is the same as the current capacity - if (value < Length) throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + if (value < Length) throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity); Contract.Ensures(_capacity - _origin == value); Contract.EndContractBlock(); @@ -346,14 +346,14 @@ namespace System.IO set { if (value < 0) - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Position == value); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); if (value > MemStreamMaxLength) - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength); _position = _origin + (int)value; } } @@ -361,13 +361,13 @@ namespace System.IO public override int Read([In, Out] byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); @@ -395,13 +395,13 @@ namespace System.IO public override Task<int> ReadAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // contract validation copied from Read(...) // If cancellation was requested, bail early @@ -513,14 +513,14 @@ namespace System.IO if (!_isOpen) __Error.StreamIsClosed(); if (offset > MemStreamMaxLength) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_StreamLength); switch (loc) { case SeekOrigin.Begin: { int tempPosition = unchecked(_origin + (int)offset); if (offset < 0 || tempPosition < _origin) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); _position = tempPosition; break; } @@ -528,7 +528,7 @@ namespace System.IO { int tempPosition = unchecked(_position + (int)offset); if (unchecked(_position + offset) < _origin || tempPosition < _origin) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); _position = tempPosition; break; } @@ -536,12 +536,12 @@ namespace System.IO { int tempPosition = unchecked(_length + (int)offset); if (unchecked(_length + offset) < _origin || tempPosition < _origin) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); _position = tempPosition; break; } default: - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSeekOrigin")); + throw new ArgumentException(SR.Argument_InvalidSeekOrigin); } Debug.Assert(_position >= 0, "_position >= 0"); @@ -562,7 +562,7 @@ namespace System.IO { if (value < 0 || value > Int32.MaxValue) { - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength); } Contract.Ensures(_length - _origin == value); Contract.EndContractBlock(); @@ -572,7 +572,7 @@ namespace System.IO Debug.Assert(MemStreamMaxLength == Int32.MaxValue); // Check parameter validation logic in this method if this fails. if (value > (Int32.MaxValue - _origin)) { - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength); } int newLength = _origin + (int)value; @@ -594,13 +594,13 @@ namespace System.IO public override void Write(byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); @@ -609,7 +609,7 @@ namespace System.IO int i = _position + count; // Check for overflow if (i < 0) - throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong")); + throw new IOException(SR.IO_StreamTooLong); if (i > _length) { @@ -638,13 +638,13 @@ namespace System.IO public override Task WriteAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // contract validation copied from Write(...) // If cancellation is already requested, bail early @@ -692,7 +692,7 @@ namespace System.IO public virtual void WriteTo(Stream stream) { if (stream == null) - throw new ArgumentNullException(nameof(stream), Environment.GetResourceString("ArgumentNull_Stream")); + throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); diff --git a/src/mscorlib/src/System/IO/PathTooLongException.cs b/src/mscorlib/src/System/IO/PathTooLongException.cs index 07ecb38db4..a0f176c182 100644 --- a/src/mscorlib/src/System/IO/PathTooLongException.cs +++ b/src/mscorlib/src/System/IO/PathTooLongException.cs @@ -23,7 +23,7 @@ namespace System.IO public class PathTooLongException : IOException { public PathTooLongException() - : base(Environment.GetResourceString("IO.PathTooLong")) + : base(SR.IO_PathTooLong) { SetErrorCode(__HResults.COR_E_PATHTOOLONG); } diff --git a/src/mscorlib/src/System/IO/Stream.cs b/src/mscorlib/src/System/IO/Stream.cs index 585f5999a3..92fe374f19 100644 --- a/src/mscorlib/src/System/IO/Stream.cs +++ b/src/mscorlib/src/System/IO/Stream.cs @@ -98,11 +98,11 @@ namespace System.IO get { Contract.Ensures(Contract.Result<int>() >= 0); - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TimeoutsNotSupported")); + throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported); } set { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TimeoutsNotSupported")); + throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported); } } @@ -111,11 +111,11 @@ namespace System.IO get { Contract.Ensures(Contract.Result<int>() >= 0); - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TimeoutsNotSupported")); + throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported); } set { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TimeoutsNotSupported")); + throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported); } } @@ -382,15 +382,15 @@ namespace System.IO if (readTask == null) { - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple); } else if (readTask != asyncResult) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple")); + throw new InvalidOperationException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple); } else if (!readTask._isRead) { - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple); } try @@ -566,15 +566,15 @@ namespace System.IO var writeTask = _activeReadWriteTask; if (writeTask == null) { - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple); } else if (writeTask != asyncResult) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple")); + throw new InvalidOperationException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple); } else if (writeTask._isRead) { - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple); } try diff --git a/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs b/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs index 8ff0e045ca..45bbd816df 100644 --- a/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs +++ b/src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs @@ -17,29 +17,29 @@ namespace System.IO if (bufferSize <= 0) { - throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, SR.ArgumentOutOfRange_NeedPosNum); } bool sourceCanRead = source.CanRead; if (!sourceCanRead && !source.CanWrite) { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed")); + throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed); } bool destinationCanWrite = destination.CanWrite; if (!destinationCanWrite && !destination.CanRead) { - throw new ObjectDisposedException(nameof(destination), Environment.GetResourceString("ObjectDisposed_StreamClosed")); + throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed); } if (!sourceCanRead) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream")); + throw new NotSupportedException(SR.NotSupported_UnreadableStream); } if (!destinationCanWrite) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream")); + throw new NotSupportedException(SR.NotSupported_UnwritableStream); } } } diff --git a/src/mscorlib/src/System/IO/StreamReader.cs b/src/mscorlib/src/System/IO/StreamReader.cs index c86e974307..eedf6e7289 100644 --- a/src/mscorlib/src/System/IO/StreamReader.cs +++ b/src/mscorlib/src/System/IO/StreamReader.cs @@ -103,7 +103,7 @@ namespace System.IO Task t = _asyncReadTask; if (t != null && !t.IsCompleted) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsyncIOInProgress")); + throw new InvalidOperationException(SR.InvalidOperation_AsyncIOInProgress); } // StreamReader by default will ignore illegal UTF8 characters. We don't want to @@ -149,9 +149,9 @@ namespace System.IO if (stream == null || encoding == null) throw new ArgumentNullException((stream == null ? nameof(stream) : nameof(encoding))); if (!stream.CanRead) - throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); + throw new ArgumentException(SR.Argument_StreamNotReadable); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum); Contract.EndContractBlock(); Init(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen); @@ -181,9 +181,9 @@ namespace System.IO if (path==null || encoding==null) throw new ArgumentNullException((path==null ? nameof(path) : nameof(encoding))); if (path.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); + throw new ArgumentException(SR.Argument_EmptyPath); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum); Contract.EndContractBlock(); Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultFileStreamBufferSize, FileOptions.SequentialScan); @@ -338,11 +338,11 @@ namespace System.IO public override int Read([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); if (stream == null) @@ -396,11 +396,11 @@ namespace System.IO public override int ReadBlock([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); if (stream == null) @@ -872,11 +872,11 @@ namespace System.IO public override Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // If we have been inherited into a subclass, the following implementation could be incorrect @@ -1058,11 +1058,11 @@ namespace System.IO public override Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // If we have been inherited into a subclass, the following implementation could be incorrect diff --git a/src/mscorlib/src/System/IO/TextReader.cs b/src/mscorlib/src/System/IO/TextReader.cs index 15ba8fba7d..3da68591b0 100644 --- a/src/mscorlib/src/System/IO/TextReader.cs +++ b/src/mscorlib/src/System/IO/TextReader.cs @@ -93,13 +93,13 @@ namespace System.IO { public virtual int Read([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0) - throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.Ensures(Contract.Result<int>() >= 0); Contract.Ensures(Contract.Result<int>() <= Contract.OldValue(count)); Contract.EndContractBlock(); @@ -192,11 +192,11 @@ namespace System.IO { public virtual Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); return ReadAsyncInternal(buffer, index, count); @@ -221,11 +221,11 @@ namespace System.IO { public virtual Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -362,11 +362,11 @@ namespace System.IO { public override Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -377,11 +377,11 @@ namespace System.IO { public override Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((index < 0 ? nameof(index) : nameof(count)), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - index < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); return Task.FromResult(Read(buffer, index, count)); diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs index 731df60bba..5f6f588cbe 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs @@ -65,15 +65,15 @@ namespace System.IO } if (offset < 0) { - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); } if (capacity < 0) { - throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum); } if (buffer.ByteLength < (UInt64)(offset + capacity)) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndCapacityOutOfBounds")); + throw new ArgumentException(SR.Argument_OffsetAndCapacityOutOfBounds); } if (access < FileAccess.Read || access > FileAccess.ReadWrite) { @@ -83,7 +83,7 @@ namespace System.IO if (_isOpen) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice")); + throw new InvalidOperationException(SR.InvalidOperation_CalledTwice); } unsafe @@ -95,7 +95,7 @@ namespace System.IO buffer.AcquirePointer(ref pointer); if (((byte*)((Int64)pointer + offset + capacity)) < pointer) { - throw new ArgumentException(Environment.GetResourceString("Argument_UnmanagedMemAccessorWrapAround")); + throw new ArgumentException(SR.Argument_UnmanagedMemAccessorWrapAround); } } finally @@ -314,7 +314,7 @@ namespace System.IO // Check for invalid Decimal values if (!((flags & ~(SignMask | ScaleMask)) == 0 && (flags & ScaleMask) <= (28 << 16))) { - throw new ArgumentException(Environment.GetResourceString("Arg_BadDecimal")); // Throw same Exception type as Decimal(int[]) ctor for compat + throw new ArgumentException(SR.Arg_BadDecimal); // Throw same Exception type as Decimal(int[]) ctor for compat } bool isNegative = (flags & SignMask) != 0; @@ -502,17 +502,17 @@ namespace System.IO { if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.EndContractBlock(); if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } if (!CanRead) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading")); + throw new NotSupportedException(SR.NotSupported_Reading); } UInt32 sizeOfT = Marshal.SizeOfType(typeof(T)); @@ -520,11 +520,11 @@ namespace System.IO { if (position >= _capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead", typeof(T).FullName), nameof(position)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToRead, typeof (T).FullName), nameof(position)); } } @@ -545,31 +545,31 @@ namespace System.IO } if (offset < 0) { - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); } if (array.Length - offset < count) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndLengthOutOfBounds")); + throw new ArgumentException(SR.Argument_OffsetAndLengthOutOfBounds); } Contract.EndContractBlock(); if (!CanRead) { if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } else { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading")); + throw new NotSupportedException(SR.NotSupported_Reading); } } if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } UInt32 sizeOfT = Marshal.AlignedSizeOf<T>(); @@ -577,7 +577,7 @@ namespace System.IO // only check position and ask for fewer Ts if count is too big if (position >= _capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } int n = count; @@ -903,17 +903,17 @@ namespace System.IO { if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.EndContractBlock(); if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } if (!CanWrite) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing")); + throw new NotSupportedException(SR.NotSupported_Writing); } UInt32 sizeOfT = Marshal.SizeOfType(typeof(T)); @@ -921,11 +921,11 @@ namespace System.IO { if (position >= _capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", typeof(T).FullName), nameof(position)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, typeof (T).FullName), nameof(position)); } } @@ -943,33 +943,33 @@ namespace System.IO } if (offset < 0) { - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); } if (array.Length - offset < count) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndLengthOutOfBounds")); + throw new ArgumentException(SR.Argument_OffsetAndLengthOutOfBounds); } if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } if (position >= Capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } Contract.EndContractBlock(); if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } if (!CanWrite) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing")); + throw new NotSupportedException(SR.NotSupported_Writing); } _buffer.WriteArray<T>((UInt64)(_offset + position), array, offset, count); @@ -1031,26 +1031,26 @@ namespace System.IO { if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } if (!CanRead) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading")); + throw new NotSupportedException(SR.NotSupported_Reading); } if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.EndContractBlock(); if (position > _capacity - sizeOfType) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead"), nameof(position)); + throw new ArgumentException(SR.Argument_NotEnoughBytesToRead, nameof(position)); } } } @@ -1059,26 +1059,26 @@ namespace System.IO { if (!_isOpen) { - throw new ObjectDisposedException("UnmanagedMemoryAccessor", Environment.GetResourceString("ObjectDisposed_ViewAccessorClosed")); + throw new ObjectDisposedException("UnmanagedMemoryAccessor", SR.ObjectDisposed_ViewAccessorClosed); } if (!CanWrite) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing")); + throw new NotSupportedException(SR.NotSupported_Writing); } if (position < 0) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum); } Contract.EndContractBlock(); if (position > _capacity - sizeOfType) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", nameof(Byte)), nameof(position)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, nameof(Byte)), nameof(position)); } } } diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs index 086c19bafa..f21fe47371 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs @@ -126,15 +126,15 @@ namespace System.IO } if (offset < 0) { - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); } if (length < 0) { - throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum); } if (buffer.ByteLength < (ulong)(offset + length)) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSafeBufferOffLen")); + throw new ArgumentException(SR.Argument_InvalidSafeBufferOffLen); } if (access < FileAccess.Read || access > FileAccess.ReadWrite) { @@ -144,7 +144,7 @@ namespace System.IO if (_isOpen) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice")); + throw new InvalidOperationException(SR.InvalidOperation_CalledTwice); } // check for wraparound @@ -157,7 +157,7 @@ namespace System.IO buffer.AcquirePointer(ref pointer); if ((pointer + offset + length) < pointer) { - throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround")); + throw new ArgumentException(SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround); } } finally @@ -195,17 +195,17 @@ namespace System.IO if (pointer == null) throw new ArgumentNullException(nameof(pointer)); if (length < 0 || capacity < 0) - throw new ArgumentOutOfRangeException((length < 0) ? nameof(length) : nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException((length < 0) ? nameof(length) : nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum); if (length > capacity) - throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_LengthGreaterThanCapacity")); + throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_LengthGreaterThanCapacity); Contract.EndContractBlock(); // Check for wraparound. if (((byte*)((long)pointer + capacity)) < pointer) - throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround")); + throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround); if (access < FileAccess.Read || access > FileAccess.ReadWrite) - throw new ArgumentOutOfRangeException(nameof(access), Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(access), SR.ArgumentOutOfRange_Enum); if (_isOpen) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice")); + throw new InvalidOperationException(SR.InvalidOperation_CalledTwice); _mem = pointer; _offset = 0; @@ -295,7 +295,7 @@ namespace System.IO set { if (value < 0) - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum); Contract.EndContractBlock(); if (!CanSeek) __Error.StreamIsClosed(); @@ -303,7 +303,7 @@ namespace System.IO unsafe { // On 32 bit machines, ensure we don't wrap around. if (value > (long) Int32.MaxValue || _mem + value < _mem) - throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength); } #endif Interlocked.Exchange(ref _position, value); @@ -317,13 +317,13 @@ namespace System.IO { if (_buffer != null) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UmsSafeBuffer")); + throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer); } // Use a temp to avoid a race long pos = Interlocked.Read(ref _position); if (pos > _capacity) - throw new IndexOutOfRangeException(Environment.GetResourceString("IndexOutOfRange_UMSPosition")); + throw new IndexOutOfRangeException(SR.IndexOutOfRange_UMSPosition); byte* ptr = _mem + pos; if (!_isOpen) __Error.StreamIsClosed(); return ptr; @@ -331,15 +331,15 @@ namespace System.IO set { if (_buffer != null) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UmsSafeBuffer")); + throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer); if (!_isOpen) __Error.StreamIsClosed(); // Note: subtracting pointers returns an Int64. Working around // to avoid hitting compiler warning CS0652 on this line. if (new IntPtr(value - _mem).ToInt64() > UnmanagedMemStreamMaxLength) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamLength")); + throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength); if (value < _mem) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); Interlocked.Exchange(ref _position, value - _mem); } @@ -350,7 +350,7 @@ namespace System.IO get { if (_buffer != null) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UmsSafeBuffer")); + throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer); return _mem; } @@ -359,13 +359,13 @@ namespace System.IO public override int Read([In, Out] byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // Keep this in sync with contract validation in ReadAsync if (!_isOpen) __Error.StreamIsClosed(); @@ -421,13 +421,13 @@ namespace System.IO public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // contract validation copied from Read(...) if (cancellationToken.IsCancellationRequested) @@ -491,31 +491,31 @@ namespace System.IO { if (!_isOpen) __Error.StreamIsClosed(); if (offset > UnmanagedMemStreamMaxLength) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamLength")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_UnmanagedMemStreamLength); switch (loc) { case SeekOrigin.Begin: if (offset < 0) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); Interlocked.Exchange(ref _position, offset); break; case SeekOrigin.Current: long pos = Interlocked.Read(ref _position); if (offset + pos < 0) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); Interlocked.Exchange(ref _position, offset + pos); break; case SeekOrigin.End: long len = Interlocked.Read(ref _length); if (len + offset < 0) - throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin")); + throw new IOException(SR.IO_SeekBeforeBegin); Interlocked.Exchange(ref _position, len + offset); break; default: - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSeekOrigin")); + throw new ArgumentException(SR.Argument_InvalidSeekOrigin); } long finalPos = Interlocked.Read(ref _position); @@ -526,15 +526,15 @@ namespace System.IO public override void SetLength(long value) { if (value < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException("length", SR.ArgumentOutOfRange_NeedNonNegNum); Contract.EndContractBlock(); if (_buffer != null) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UmsSafeBuffer")); + throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer); if (!_isOpen) __Error.StreamIsClosed(); if (!CanWrite) __Error.WriteNotSupported(); if (value > _capacity) - throw new IOException(Environment.GetResourceString("IO.IO_FixedCapacity")); + throw new IOException(SR.IO_FixedCapacity); long pos = Interlocked.Read(ref _position); long len = Interlocked.Read(ref _length); @@ -555,13 +555,13 @@ namespace System.IO public override void Write(byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // Keep contract validation in sync with WriteAsync(..) if (!_isOpen) __Error.StreamIsClosed(); @@ -572,11 +572,11 @@ namespace System.IO long n = pos + count; // Check for overflow if (n < 0) - throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong")); + throw new IOException(SR.IO_StreamTooLong); if (n > _capacity) { - throw new NotSupportedException(Environment.GetResourceString("IO.IO_FixedCapacity")); + throw new NotSupportedException(SR.IO_FixedCapacity); } if (_buffer == null) @@ -607,7 +607,7 @@ namespace System.IO long bytesLeft = _capacity - pos; if (bytesLeft < count) { - throw new ArgumentException(Environment.GetResourceString("Arg_BufferTooSmall")); + throw new ArgumentException(SR.Arg_BufferTooSmall); } byte* pointer = null; @@ -638,13 +638,13 @@ namespace System.IO public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer); if (offset < 0) - throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + throw new ArgumentException(SR.Argument_InvalidOffLen); Contract.EndContractBlock(); // contract validation copied from Write(..) if (cancellationToken.IsCancellationRequested) @@ -675,10 +675,10 @@ namespace System.IO { // Check for overflow if (n < 0) - throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong")); + throw new IOException(SR.IO_StreamTooLong); if (n > _capacity) - throw new NotSupportedException(Environment.GetResourceString("IO.IO_FixedCapacity")); + throw new NotSupportedException(SR.IO_FixedCapacity); // Check to see whether we are now expanding the stream and must // zero any memory in the middle. diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs index 04d5be3c5e..86e4707dfd 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs @@ -70,7 +70,7 @@ namespace System.IO public override byte[] GetBuffer() { - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_MemStreamBuffer")); + throw new UnauthorizedAccessException(SR.UnauthorizedAccess_MemStreamBuffer); } public override bool TryGetBuffer(out ArraySegment<byte> buffer) @@ -88,7 +88,7 @@ namespace System.IO [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. set { - throw new IOException(Environment.GetResourceString("IO.IO_FixedCapacity")); + throw new IOException(SR.IO_FixedCapacity); } } @@ -151,7 +151,7 @@ namespace System.IO public unsafe override void WriteTo(Stream stream) { if (stream == null) - throw new ArgumentNullException(nameof(stream), Environment.GetResourceString("ArgumentNull_Stream")); + throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream); Contract.EndContractBlock(); if (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); @@ -178,19 +178,19 @@ namespace System.IO throw new ArgumentNullException(nameof(destination)); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum); if (!CanRead && !CanWrite) - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed")); + throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed); if (!destination.CanRead && !destination.CanWrite) - throw new ObjectDisposedException(nameof(destination), Environment.GetResourceString("ObjectDisposed_StreamClosed")); + throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed); if (!CanRead) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream")); + throw new NotSupportedException(SR.NotSupported_UnreadableStream); if (!destination.CanWrite) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream")); + throw new NotSupportedException(SR.NotSupported_UnwritableStream); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/IO/__Error.cs b/src/mscorlib/src/System/IO/__Error.cs index 14c8eb9f3b..70f83261ed 100644 --- a/src/mscorlib/src/System/IO/__Error.cs +++ b/src/mscorlib/src/System/IO/__Error.cs @@ -30,49 +30,49 @@ namespace System.IO { internal static void EndOfFile() { - throw new EndOfStreamException(Environment.GetResourceString("IO.EOF_ReadBeyondEOF")); + throw new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF); } internal static void FileNotOpen() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_FileClosed")); + throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed); } internal static void StreamIsClosed() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed")); + throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed); } internal static void MemoryStreamNotExpandable() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_MemStreamNotExpandable")); + throw new NotSupportedException(SR.NotSupported_MemStreamNotExpandable); } internal static void ReaderClosed() { - throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ReaderClosed")); + throw new ObjectDisposedException(null, SR.ObjectDisposed_ReaderClosed); } internal static void ReadNotSupported() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream")); + throw new NotSupportedException(SR.NotSupported_UnreadableStream); } internal static void WrongAsyncResult() { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongAsyncResult")); + throw new ArgumentException(SR.Arg_WrongAsyncResult); } internal static void EndReadCalledTwice() { // Should ideally be InvalidOperationExc but we can't maitain parity with Stream and FileStream without some work - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EndReadCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_EndReadCalledMultiple); } internal static void EndWriteCalledTwice() { // Should ideally be InvalidOperationExc but we can't maintain parity with Stream and FileStream without some work - throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EndWriteCalledMultiple")); + throw new ArgumentException(SR.InvalidOperation_EndWriteCalledMultiple); } // Given a possible fully qualified path, ensure that we have path @@ -124,7 +124,7 @@ namespace System.IO if (!safeToReturn) { if (PathInternal.IsDirectorySeparator(path[path.Length - 1])) - path = Environment.GetResourceString("IO.IO_NoPermissionToDirectoryName"); + path = SR.IO_NoPermissionToDirectoryName; else path = Path.GetFileName(path); } @@ -153,46 +153,46 @@ namespace System.IO { case Win32Native.ERROR_FILE_NOT_FOUND: if (str.Length == 0) - throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound")); + throw new FileNotFoundException(SR.IO_FileNotFound); else - throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound_FileName", str), str); + throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, str), str); case Win32Native.ERROR_PATH_NOT_FOUND: if (str.Length == 0) - throw new DirectoryNotFoundException(Environment.GetResourceString("IO.PathNotFound_NoPathName")); + throw new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName); else - throw new DirectoryNotFoundException(Environment.GetResourceString("IO.PathNotFound_Path", str)); + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, str)); case Win32Native.ERROR_ACCESS_DENIED: if (str.Length == 0) - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_IODenied_NoPathName")); + throw new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName); else - throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", str)); + throw new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, str)); case Win32Native.ERROR_ALREADY_EXISTS: if (str.Length == 0) goto default; - throw new IOException(Environment.GetResourceString("IO.IO_AlreadyExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); case Win32Native.ERROR_FILENAME_EXCED_RANGE: - throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong")); + throw new PathTooLongException(SR.IO_PathTooLong); case Win32Native.ERROR_INVALID_DRIVE: - throw new DriveNotFoundException(Environment.GetResourceString("IO.DriveNotFound_Drive", str)); + throw new DriveNotFoundException(SR.Format(SR.IO_DriveNotFound_Drive, str)); case Win32Native.ERROR_INVALID_PARAMETER: throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); case Win32Native.ERROR_SHARING_VIOLATION: if (str.Length == 0) - throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_NoFileName"), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + throw new IOException(SR.IO_SharingViolation_NoFileName, Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); else - throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_File", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + throw new IOException(SR.Format(SR.IO_SharingViolation_File, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); case Win32Native.ERROR_FILE_EXISTS: if (str.Length == 0) goto default; - throw new IOException(Environment.GetResourceString("IO.IO_FileExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); + throw new IOException(SR.Format(SR.IO_FileExists_Name, str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath); case Win32Native.ERROR_OPERATION_ABORTED: throw new OperationCanceledException(); @@ -204,7 +204,7 @@ namespace System.IO internal static void WriteNotSupported() { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream")); + throw new NotSupportedException(SR.NotSupported_UnwritableStream); } // From WinError.h |