// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(String chars, int charIndex, int charCount,
+ public override int GetBytes(String chars, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- 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_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- 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)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ // NOTE: Will throw ArgumentNull of "s" is chars is null.
+ return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes
// Call the internal version, with an empty encoder
return encoding.GetByteCount(chars, count, encoder: null);
}
+
+ public unsafe static int GetBytes(Encoding encoding, string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
+ {
+ Contract.Assert(encoding != null);
+ if (s == null || bytes == null)
+ {
+ throw new ArgumentNullException(s == null ? "s" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
+ }
+ if (charIndex < 0 || charCount < 0)
+ {
+ throw new ArgumentOutOfRangeException(charIndex < 0 ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ }
+ if (s.Length - charIndex < charCount)
+ {
+ throw new ArgumentOutOfRangeException("s", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
+ }
+ if (byteIndex < 0 || byteIndex > bytes.Length)
+ {
+ throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+ }
+ Contract.EndContractBlock();
+
+ int byteCount = bytes.Length - byteIndex;
+
+ // Fixed doesn't like empty arrays
+ // TODO: Consider just throwing an
+ // exception here instead of allocating
+ // a new array, if (byteCount == 0)
+ if (bytes.Length == 0)
+ bytes = new byte[1];
+
+ fixed (char* pChars = s) fixed (byte* pBytes = bytes)
+ {
+ return encoding.GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, encoder: null);
+ }
+ }
}
}
// So if you fix this, fix the others. Currently those include:
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
[System.Security.SecuritySafeCritical] // overrides public transparent member
- public override unsafe int GetBytes(String s, int charIndex, int charCount,
+ public override int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- if (s == null || bytes == null)
- throw new ArgumentNullException((s == null ? "s" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("s",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s)
- fixed ( byte* pBytes = bytes)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, s, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(String s, int charIndex, int charCount,
+ public override int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- if (s == null || bytes == null)
- throw new ArgumentNullException((s == null ? "s" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("s",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- 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 = s)
- fixed ( byte* pBytes = bytes)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, s, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes
[System.Security.SecuritySafeCritical] // auto-generated
[System.Runtime.InteropServices.ComVisible(false)]
- public override unsafe int GetBytes(String s, int charIndex, int charCount,
+ public override int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- if (s == null || bytes == null)
- throw new ArgumentNullException((s == null ? "s" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("s",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s)
- fixed ( byte* pBytes = bytes)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, s, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(String s, int charIndex, int charCount,
+ public override int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- if (s == null || bytes == null)
- throw new ArgumentNullException((s == null ? "s" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("s",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s)
- fixed ( byte* pBytes = bytes)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, s, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetBytes(String s, int charIndex, int charCount,
+ public override int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
- if (s == null || bytes == null)
- throw new ArgumentNullException((s == null ? "s" : "bytes"),
- Environment.GetResourceString("ArgumentNull_Array"));
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"),
- Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException("s",
- Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException("byteIndex",
- Environment.GetResourceString("ArgumentOutOfRange_Index"));
- Contract.EndContractBlock();
-
- int byteCount = bytes.Length - byteIndex;
-
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s)
- fixed ( byte* pBytes = bytes)
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, null);
+ return EncodingForwarder.GetBytes(this, s, charIndex, charCount, bytes, byteIndex);
}
// Encodes a range of characters in a character array into a range of bytes