using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Text { /// Represents a UTF-16 encoding of Unicode characters. /// 1 // Token: 0x02000604 RID: 1540 [ComVisible(true)] [MonoTODO("Serialization format not compatible with .NET")] [Serializable] public class UnicodeEncoding : Encoding { /// Initializes a new instance of the class. // Token: 0x06003862 RID: 14434 RVA: 0x000C2E7C File Offset: 0x000C107C public UnicodeEncoding() : this(false, true) { this.bigEndian = false; this.byteOrderMark = true; } /// Initializes a new instance of the class. Parameters specify whether to use the big endian byte order and whether to provide a Unicode byte order mark. /// true to use the big endian byte order (most significant byte first), or false to use the little endian byte order (least significant byte first). /// true to specify that a Unicode byte order mark is provided; otherwise, false. // Token: 0x06003863 RID: 14435 RVA: 0x000C2E94 File Offset: 0x000C1094 public UnicodeEncoding(bool bigEndian, bool byteOrderMark) : this(bigEndian, byteOrderMark, false) { } /// Initializes a new instance of the class. Parameters specify whether to use the big endian byte order, whether to provide a Unicode byte order mark, and whether to throw an exception when an invalid encoding is detected. /// true to use the big endian byte order (most significant byte first); false to use the little endian byte order (least significant byte first). /// true to specify that a Unicode byte order mark is provided; otherwise, false. /// true to specify that an exception should be thrown when an invalid encoding is detected; otherwise, false. // Token: 0x06003864 RID: 14436 RVA: 0x000C2EA0 File Offset: 0x000C10A0 public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes) : base((!bigEndian) ? 1200 : 1201) { if (throwOnInvalidBytes) { base.SetFallbackInternal(null, new DecoderExceptionFallback()); } else { base.SetFallbackInternal(null, new DecoderReplacementFallback("\ufffd")); } this.bigEndian = bigEndian; this.byteOrderMark = byteOrderMark; if (bigEndian) { this.body_name = "unicodeFFFE"; this.encoding_name = "Unicode (Big-Endian)"; this.header_name = "unicodeFFFE"; this.is_browser_save = false; this.web_name = "unicodeFFFE"; } else { this.body_name = "utf-16"; this.encoding_name = "Unicode"; this.header_name = "utf-16"; this.is_browser_save = true; this.web_name = "utf-16"; } this.windows_code_page = 1200; } /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. /// The number of bytes produced by encoding the specified characters. /// The character array containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// /// is null (Nothing). /// /// or is less than zero.-or- and do not denote a valid range in .-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003865 RID: 14437 RVA: 0x000C2F7C File Offset: 0x000C117C public override int GetByteCount(char[] chars, int index, int count) { if (chars == null) { throw new ArgumentNullException("chars"); } if (index < 0 || index > chars.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > chars.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } return count * 2; } /// Calculates the number of bytes produced by encoding the characters in the specified . /// The number of bytes produced by encoding the specified characters. /// The containing the set of characters to encode. /// /// is null (Nothing). /// The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003866 RID: 14438 RVA: 0x000C2FEC File Offset: 0x000C11EC public override int GetByteCount(string s) { if (s == null) { throw new ArgumentNullException("s"); } return s.Length * 2; } /// Calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer. /// The number of bytes produced by encoding the specified characters. /// A pointer to the first character to encode. /// The number of characters to encode. /// /// is null (Nothing in Visual Basic .NET). /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled and contains an invalid sequence of characters. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003867 RID: 14439 RVA: 0x000C3008 File Offset: 0x000C1208 [ComVisible(false)] [CLSCompliant(false)] public unsafe override int GetByteCount(char* chars, int count) { if (chars == null) { throw new ArgumentNullException("chars"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } return count * 2; } /// Encodes a set of characters from the specified character array into the specified byte array. /// The actual number of bytes written into . /// The character array containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. /// The index at which to start writing the resulting sequence of bytes. /// /// is null (Nothing).-or- is null (Nothing). /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of characters.-or- does not have enough capacity from to the end of the array to accommodate the resulting bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003868 RID: 14440 RVA: 0x000C303C File Offset: 0x000C123C public unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (chars == null) { throw new ArgumentNullException("chars"); } if (bytes == null) { throw new ArgumentNullException("bytes"); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } if (charCount < 0 || charCount > chars.Length - charIndex) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_Array")); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (charCount == 0) { return 0; } int num = bytes.Length - byteIndex; if (bytes.Length == 0) { bytes = new byte[1]; } fixed (char* ptr = (ref chars != null && chars.Length != 0 ? ref chars[0] : ref *null)) { fixed (byte* ptr2 = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { return this.GetBytesInternal(ptr + charIndex, charCount, ptr2 + byteIndex, num); } } } /// Encodes a set of characters from the specified into the specified byte array. /// The actual number of bytes written into . /// The containing the set of characters to encode. /// The index of the first character to encode. /// The number of characters to encode. /// The byte array to contain the resulting sequence of bytes. /// The index at which to start writing the resulting sequence of bytes. /// /// is null (Nothing).-or- is null (Nothing). /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of characters.-or- does not have enough capacity from to the end of the array to accommodate the resulting bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003869 RID: 14441 RVA: 0x000C3150 File Offset: 0x000C1350 public unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { if (s == null) { throw new ArgumentNullException("s"); } if (bytes == null) { throw new ArgumentNullException("bytes"); } if (charIndex < 0 || charIndex > s.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_StringIndex")); } if (charCount < 0 || charCount > s.Length - charIndex) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_StringRange")); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (charCount == 0) { return 0; } int num = bytes.Length - byteIndex; if (bytes.Length == 0) { bytes = new byte[1]; } fixed (char* ptr = s + RuntimeHelpers.OffsetToStringData / 2) { fixed (byte* ptr2 = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { return this.GetBytesInternal(ptr + charIndex, charCount, ptr2 + byteIndex, num); } } } /// Encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer. /// The actual number of bytes written at the location indicated by the parameter. /// A pointer to the first character to encode. /// The number of characters to encode. /// A pointer to the location at which to start writing the resulting sequence of bytes. /// The maximum number of bytes to write. /// /// is null (Nothing).-or- is null (Nothing). /// /// or is less than zero. /// Error detection is enabled, and contains an invalid sequence of characters.-or- is less than the resulting number of bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x0600386A RID: 14442 RVA: 0x000C3258 File Offset: 0x000C1458 [CLSCompliant(false)] [ComVisible(false)] public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount"); } if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount"); } return this.GetBytesInternal(chars, charCount, bytes, byteCount); } // Token: 0x0600386B RID: 14443 RVA: 0x000C32B8 File Offset: 0x000C14B8 private unsafe int GetBytesInternal(char* chars, int charCount, byte* bytes, int byteCount) { int num = charCount * 2; if (byteCount < num) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } UnicodeEncoding.CopyChars((byte*)chars, bytes, num, this.bigEndian); return num; } /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. /// The number of characters produced by decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// /// is null (Nothing). /// /// or is less than zero.-or- and do not denote a valid range in .-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x0600386C RID: 14444 RVA: 0x000C32F0 File Offset: 0x000C14F0 public override int GetCharCount(byte[] bytes, int index, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (index < 0 || index > bytes.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > bytes.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } return count / 2; } /// Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. /// The number of characters produced by decoding the specified sequence of bytes. /// A pointer to the first byte to decode. /// The number of bytes to decode. /// /// is null (Nothing). /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x0600386D RID: 14445 RVA: 0x000C3360 File Offset: 0x000C1560 [ComVisible(false)] [CLSCompliant(false)] public unsafe override int GetCharCount(byte* bytes, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } return count / 2; } /// Decodes a sequence of bytes from the specified byte array into the specified character array. /// The actual number of characters written into . /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// The character array to contain the resulting set of characters. /// The index at which to start writing the resulting set of characters. /// /// is null (Nothing).-or- is null (Nothing). /// /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . /// Error detection is enabled, and contains an invalid sequence of bytes.-or- does not have enough capacity from to the end of the array to accommodate the resulting characters. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x0600386E RID: 14446 RVA: 0x000C3394 File Offset: 0x000C1594 public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (byteCount < 0 || byteCount > bytes.Length - byteIndex) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_Array")); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } if (byteCount == 0) { return 0; } int num = chars.Length - charIndex; if (chars.Length == 0) { chars = new char[1]; } fixed (byte* ptr = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { fixed (char* ptr2 = (ref chars != null && chars.Length != 0 ? ref chars[0] : ref *null)) { return this.GetCharsInternal(ptr + byteIndex, byteCount, ptr2 + charIndex, num); } } } /// Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer. /// The actual number of characters written at the location indicated by the parameter. /// A pointer to the first byte to decode. /// The number of bytes to decode. /// A pointer to the location at which to start writing the resulting set of characters. /// The maximum number of characters to write. /// /// is null (Nothing).-or- is null (Nothing). /// /// or is less than zero. /// Error detection is enabled, and contains an invalid sequence of bytes.-or- is less than the resulting number of characters. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x0600386F RID: 14447 RVA: 0x000C34A8 File Offset: 0x000C16A8 [ComVisible(false)] [CLSCompliant(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount"); } if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount"); } return this.GetCharsInternal(bytes, byteCount, chars, charCount); } /// Decodes a range of bytes from a byte array into a string. /// A object containing the results of decoding the specified sequence of bytes. /// The byte array containing the sequence of bytes to decode. /// The index of the first byte to decode. /// The number of bytes to decode. /// /// is null (Nothing). /// /// or is less than zero.-or- and do not denote a valid range in . /// Error detection is enabled, and contains an invalid sequence of bytes. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003870 RID: 14448 RVA: 0x000C3508 File Offset: 0x000C1708 [ComVisible(false)] public unsafe override string GetString(byte[] bytes, int index, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (index < 0 || index > bytes.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > bytes.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } if (count == 0) { return string.Empty; } int num = count / 2; string text = string.InternalAllocateStr(num); fixed (byte* ptr = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { fixed (string text2 = text) { fixed (char* ptr2 = text2 + RuntimeHelpers.OffsetToStringData / 2) { this.GetCharsInternal(ptr + index, count, ptr2, num); text2 = null; ptr = null; return text; } } } } // Token: 0x06003871 RID: 14449 RVA: 0x000C35C8 File Offset: 0x000C17C8 private unsafe int GetCharsInternal(byte* bytes, int byteCount, char* chars, int charCount) { int num = byteCount / 2; if (charCount < num) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } UnicodeEncoding.CopyChars(bytes, (byte*)chars, byteCount, this.bigEndian); return num; } /// Obtains an encoder that converts a sequence of Unicode characters into a UTF-16 encoded sequence of bytes. /// A object that converts a sequence of Unicode characters into a UTF-16 encoded sequence of bytes. /// 1 // Token: 0x06003872 RID: 14450 RVA: 0x000C3600 File Offset: 0x000C1800 [ComVisible(false)] public override Encoder GetEncoder() { return base.GetEncoder(); } /// Calculates the maximum number of bytes produced by encoding the specified number of characters. /// The maximum number of bytes produced by encoding the specified number of characters. /// The number of characters to encode. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003873 RID: 14451 RVA: 0x000C3608 File Offset: 0x000C1808 public override int GetMaxByteCount(int charCount) { if (charCount < 0) { throw new ArgumentOutOfRangeException("charCount", Encoding._("ArgRange_NonNegative")); } return charCount * 2; } /// Calculates the maximum number of characters produced by decoding the specified number of bytes. /// The maximum number of characters produced by decoding the specified number of bytes. /// The number of bytes to decode. /// /// is less than zero.-or- The resulting number of bytes is greater than the maximum number that can be returned as an integer. /// A fallback occurred (see Understanding Encodings for fuller explanation)-and- is set to . /// 1 // Token: 0x06003874 RID: 14452 RVA: 0x000C362C File Offset: 0x000C182C public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_NonNegative")); } return byteCount / 2; } /// Obtains a decoder that converts a UTF-16 encoded sequence of bytes into a sequence of Unicode characters. /// A that converts a UTF-16 encoded sequence of bytes into a sequence of Unicode characters. /// 1 // Token: 0x06003875 RID: 14453 RVA: 0x000C3650 File Offset: 0x000C1850 public override Decoder GetDecoder() { return new UnicodeEncoding.UnicodeDecoder(this.bigEndian); } /// Returns a Unicode byte order mark encoded in UTF-16 format, if the constructor for this instance requests a byte order mark. /// A byte array containing the Unicode byte order mark, if the constructor for this instance requests a byte order mark. Otherwise, this method returns a byte array of length zero. /// 1 // Token: 0x06003876 RID: 14454 RVA: 0x000C3660 File Offset: 0x000C1860 public override byte[] GetPreamble() { if (this.byteOrderMark) { byte[] array = new byte[2]; if (this.bigEndian) { array[0] = 254; array[1] = byte.MaxValue; } else { array[0] = byte.MaxValue; array[1] = 254; } return array; } return new byte[0]; } /// Determines whether the specified is equal to the current object. /// true if is an instance of and is equal to the current object; otherwise, false. /// The to compare with the current object. /// 2 // Token: 0x06003877 RID: 14455 RVA: 0x000C36B8 File Offset: 0x000C18B8 public override bool Equals(object value) { UnicodeEncoding unicodeEncoding = value as UnicodeEncoding; return unicodeEncoding != null && (this.codePage == unicodeEncoding.codePage && this.bigEndian == unicodeEncoding.bigEndian) && this.byteOrderMark == unicodeEncoding.byteOrderMark; } /// Returns the hash code for the current instance. /// The hash code for the current object. /// 1 // Token: 0x06003878 RID: 14456 RVA: 0x000C3708 File Offset: 0x000C1908 public override int GetHashCode() { return base.GetHashCode(); } // Token: 0x06003879 RID: 14457 RVA: 0x000C3710 File Offset: 0x000C1910 private unsafe static void CopyChars(byte* src, byte* dest, int count, bool bigEndian) { if (BitConverter.IsLittleEndian != bigEndian) { string.memcpy(dest, src, count & -2); return; } switch (count) { case 0: return; case 1: return; case 2: goto IL_220; case 3: goto IL_220; case 4: goto IL_1F1; case 5: goto IL_1F1; case 6: goto IL_1F1; case 7: goto IL_1F1; case 8: break; case 9: break; case 10: break; case 11: break; case 12: break; case 13: break; case 14: break; case 15: break; default: do { *dest = src[1]; dest[1] = *src; dest[2] = src[3]; dest[3] = src[2]; dest[4] = src[5]; dest[5] = src[4]; dest[6] = src[7]; dest[7] = src[6]; dest[8] = src[9]; dest[9] = src[8]; dest[10] = src[11]; dest[11] = src[10]; dest[12] = src[13]; dest[13] = src[12]; dest[14] = src[15]; dest[15] = src[14]; dest += 16; src += 16; count -= 16; } while ((count & -16) != 0); switch (count) { case 0: return; case 1: return; case 2: goto IL_220; case 3: goto IL_220; case 4: goto IL_1F1; case 5: goto IL_1F1; case 6: goto IL_1F1; case 7: goto IL_1F1; } break; } *dest = src[1]; dest[1] = *src; dest[2] = src[3]; dest[3] = src[2]; dest[4] = src[5]; dest[5] = src[4]; dest[6] = src[7]; dest[7] = src[6]; dest += 8; src += 8; if ((count & 4) == 0) { goto IL_217; } IL_1F1: *dest = src[1]; dest[1] = *src; dest[2] = src[3]; dest[3] = src[2]; dest += 4; src += 4; IL_217: if ((count & 2) == 0) { return; } IL_220: *dest = src[1]; dest[1] = *src; } // Token: 0x040016D1 RID: 5841 internal const int UNICODE_CODE_PAGE = 1200; // Token: 0x040016D2 RID: 5842 internal const int BIG_UNICODE_CODE_PAGE = 1201; /// Represents the Unicode version 2.0 character size in bytes. This field is a constant. /// 1 // Token: 0x040016D3 RID: 5843 public const int CharSize = 2; // Token: 0x040016D4 RID: 5844 private bool bigEndian; // Token: 0x040016D5 RID: 5845 private bool byteOrderMark; // Token: 0x02000605 RID: 1541 private sealed class UnicodeDecoder : Decoder { // Token: 0x0600387A RID: 14458 RVA: 0x000C394C File Offset: 0x000C1B4C public UnicodeDecoder(bool bigEndian) { this.bigEndian = bigEndian; this.leftOverByte = -1; } // Token: 0x0600387B RID: 14459 RVA: 0x000C3964 File Offset: 0x000C1B64 public override int GetCharCount(byte[] bytes, int index, int count) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (index < 0 || index > bytes.Length) { throw new ArgumentOutOfRangeException("index", Encoding._("ArgRange_Array")); } if (count < 0 || count > bytes.Length - index) { throw new ArgumentOutOfRangeException("count", Encoding._("ArgRange_Array")); } if (this.leftOverByte != -1) { return (count + 1) / 2; } return count / 2; } // Token: 0x0600387C RID: 14460 RVA: 0x000C39E4 File Offset: 0x000C1BE4 public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (byteIndex < 0 || byteIndex > bytes.Length) { throw new ArgumentOutOfRangeException("byteIndex", Encoding._("ArgRange_Array")); } if (byteCount < 0 || byteCount > bytes.Length - byteIndex) { throw new ArgumentOutOfRangeException("byteCount", Encoding._("ArgRange_Array")); } if (charIndex < 0 || charIndex > chars.Length) { throw new ArgumentOutOfRangeException("charIndex", Encoding._("ArgRange_Array")); } if (byteCount == 0) { return 0; } int num = this.leftOverByte; int num2; if (num != -1) { num2 = (byteCount + 1) / 2; } else { num2 = byteCount / 2; } if (chars.Length - charIndex < num2) { throw new ArgumentException(Encoding._("Arg_InsufficientSpace")); } if (num != -1) { if (this.bigEndian) { chars[charIndex] = (char)((num << 8) | (int)bytes[byteIndex]); } else { chars[charIndex] = (char)(((int)bytes[byteIndex] << 8) | num); } charIndex++; byteIndex++; byteCount--; } if ((byteCount & -2) != 0) { fixed (byte* ptr = (ref bytes != null && bytes.Length != 0 ? ref bytes[0] : ref *null)) { fixed (char* ptr2 = (ref chars != null && chars.Length != 0 ? ref chars[0] : ref *null)) { UnicodeEncoding.CopyChars(ptr + byteIndex, (byte*)(ptr2 + charIndex), byteCount, this.bigEndian); } } } if ((byteCount & 1) == 0) { this.leftOverByte = -1; } else { this.leftOverByte = (int)bytes[byteCount + byteIndex - 1]; } return num2; } // Token: 0x040016D6 RID: 5846 private bool bigEndian; // Token: 0x040016D7 RID: 5847 private int leftOverByte; } } }