System.Text.EncodingNLS.GetBytes C# (CSharp) Method

GetBytes() private method

private GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex ) : int
chars char
charIndex int
charCount int
bytes byte
byteIndex int
return int
        public unsafe 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 ? nameof(chars): nameof(bytes)), SR.ArgumentNull_Array);

            if (charIndex < 0 || charCount < 0)
                throw new ArgumentOutOfRangeException((charIndex < 0 ? nameof(charIndex): nameof(charCount)), SR.ArgumentOutOfRange_NeedNonNegNum);

            if (chars.Length - charIndex < charCount)
                throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);

            if (byteIndex < 0 || byteIndex > bytes.Length)
                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
            Contract.EndContractBlock();

            // If nothing to encode return 0, avoid fixed problem
            if (chars.Length == 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);
        }

Same methods

EncodingNLS::GetBytes ( String s, int charIndex, int charCount, byte bytes, int byteIndex ) : int
EncodingNLS::GetBytes ( char chars, int charCount, byte bytes, int byteCount ) : int
EncodingNLS::GetBytes ( char chars, int charCount, byte bytes, int byteCount, EncoderNLS encoder ) : int

Usage Example

示例#1
0
        public override unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, bool flush)
        {
            // Validate parameters
            if (chars == null || bytes == null)
            {
                throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), SR.ArgumentNull_Array);
            }

            if (byteCount < 0 || charCount < 0)
            {
                throw new ArgumentOutOfRangeException((byteCount < 0 ? nameof(byteCount) : nameof(charCount)), SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            m_mustFlush       = flush;
            m_throwOnOverflow = true;
            return(m_encoding.GetBytes(chars, charCount, bytes, byteCount, this));
        }
All Usage Examples Of System.Text.EncodingNLS::GetBytes