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); }
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); }