diff options
Diffstat (limited to 'src/mscorlib/src/System/Text/Encoder.cs')
-rw-r--r-- | src/mscorlib/src/System/Text/Encoder.cs | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/mscorlib/src/System/Text/Encoder.cs b/src/mscorlib/src/System/Text/Encoder.cs index d223dd9d46..b9d4581276 100644 --- a/src/mscorlib/src/System/Text/Encoder.cs +++ b/src/mscorlib/src/System/Text/Encoder.cs @@ -7,6 +7,7 @@ namespace System.Text using System.Runtime.Serialization; using System.Text; using System; + using System.Diagnostics; using System.Diagnostics.Contracts; // An Encoder is used to encode a sequence of blocks of characters into // a sequence of blocks of bytes. Following instantiation of an encoder, @@ -49,13 +50,13 @@ namespace System.Text set { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Can't change fallback if buffer is wrong if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0) throw new ArgumentException( - Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), "value"); + Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), nameof(value)); m_fallback = value; m_fallbackBuffer = null; @@ -120,18 +121,17 @@ namespace System.Text // We expect this to be the workhorse for NLS encodings // unfortunately for existing overrides, it has to call the [] version, // which is really slow, so avoid this method if you might be calling external encodings. - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetByteCount(char* chars, int count, bool flush) { // Validate input parameters if (chars == null) - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -182,7 +182,6 @@ namespace System.Text // the byte[] to our byte* output buffer. If the result count was wrong, we // could easily overflow our output buffer. Therefore we do an extra test // when we copy the buffer so that we don't overflow byteCount either. - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe int GetBytes(char* chars, int charCount, @@ -190,11 +189,11 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), + throw new ArgumentOutOfRangeException((charCount<0 ? nameof(charCount) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -211,7 +210,7 @@ namespace System.Text // Do the work int result = GetBytes(arrChar, 0, charCount, arrByte, 0, flush); - Contract.Assert(result <= byteCount, "Returned more bytes than we have space for"); + Debug.Assert(result <= byteCount, "Returned more bytes than we have space for"); // Copy the byte array // WARNING: We MUST make sure that we don't copy too many bytes. We can't @@ -248,23 +247,23 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (charIndex < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"), + throw new ArgumentOutOfRangeException((charIndex<0 ? nameof(charIndex) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (byteIndex < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((byteIndex<0 ? "byteIndex" : "byteCount"), + throw new ArgumentOutOfRangeException((byteIndex<0 ? nameof(byteIndex) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -299,7 +298,6 @@ namespace System.Text // Note that if all of the input chars are not consumed, then we'll do a /2, which means // that its likely that we didn't consume as many chars as we could have. For some // applications this could be slow. (Like trying to exactly fill an output buffer from a bigger stream) - [System.Security.SecurityCritical] // auto-generated [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(false)] public virtual unsafe void Convert(char* chars, int charCount, @@ -308,10 +306,10 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), + throw new ArgumentOutOfRangeException((charCount<0 ? nameof(charCount) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); |