System.Text.UnicodeEncoding.UnicodeDecoder.GetChars C# (CSharp) Method

GetChars() public method

public GetChars ( byte bytes, int byteIndex, int byteCount, char chars, int charIndex ) : int
bytes byte
byteIndex int
byteCount int
chars char
charIndex int
return int
		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", _("ArgRange_Array"));
			}
			if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) {
				throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
			}
			if (charIndex < 0 || charIndex > chars.Length) {
				throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
			}

			if (byteCount == 0)
				return 0;

			int leftOver = leftOverByte;
			int count;

			if (leftOver != -1)
				count = (byteCount + 1) / 2;
			else
				count = byteCount / 2;

			if (chars.Length - charIndex < count)
				throw new ArgumentException (_("Arg_InsufficientSpace"));

			if (leftOver != -1) {
				if (bigEndian)
					chars [charIndex] = unchecked ((char) ((leftOver << 8) | (int) bytes [byteIndex]));
				else
					chars [charIndex] = unchecked ((char) (((int) bytes [byteIndex] << 8) | leftOver));
				charIndex++;
				byteIndex++;
				byteCount--;
			}

			if ((byteCount & unchecked ((int) 0xFFFFFFFE)) != 0)
				fixed (byte* bytePtr = bytes)
					fixed (char* charPtr = chars)
						CopyChars (bytePtr + byteIndex, (byte*) (charPtr + charIndex), byteCount, bigEndian);

			if ((byteCount & 1) == 0)
				leftOverByte = -1;
			else
				leftOverByte = bytes [byteCount + byteIndex - 1];

			return count;
		}
UnicodeEncoding.UnicodeDecoder