// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like empty byte arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
return encoding.GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, encoder: null);
}
}
+
+ public unsafe static int GetBytes(Encoding encoding, char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
+ {
+ Contract.Assert(encoding != null);
+ if (chars == null || bytes == null)
+ {
+ throw new ArgumentNullException(chars == null ? "chars" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
+ }
+ if (charIndex < 0 || charCount < 0)
+ {
+ throw new ArgumentOutOfRangeException(charIndex < 0 ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ }
+ if (chars.Length - charIndex < charCount)
+ {
+ throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
+ }
+ if (byteIndex < 0 || byteIndex > bytes.Length)
+ {
+ throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+ }
+ Contract.EndContractBlock();
+
+ // If nothing to encode return 0, avoid fixed problem
+ if (charCount == 0)
+ return 0;
+
+ // Note that this is the # of bytes to decode,
+ // not the size of the array
+ int byteCount = bytes.Length - byteIndex;
+
+ // Fixed doesn't like 0 length arrays.
+ if (bytes.Length == 0)
+ bytes = new byte[1];
+
+ // Just call the (internal) pointer version
+ fixed (char* pChars = chars) fixed (byte* pBytes = bytes)
+ {
+ return encoding.GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, encoder: null);
+ }
+ }
}
}
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
// parent method is safe
[System.Security.SecuritySafeCritical] // overrides public transparent member
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fix our input array if 0 length because fixed doesn't like 0 length arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
+ public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException((chars == null ? "chars" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("chars",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)