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

GetBytes() private method

private GetBytes ( String s, int charIndex, int charCount, byte bytes, int byteIndex ) : int
s String
charIndex int
charCount int
bytes byte
byteIndex int
return int
        public unsafe override int GetBytes(String s, int charIndex, int charCount,
                                              byte[] bytes, int byteIndex)
        {
            if (s == null || bytes == null)
                throw new ArgumentNullException((s == null ? nameof(s): nameof(bytes)), SR.ArgumentNull_Array);

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

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

            if (byteIndex < 0 || byteIndex > bytes.Length)
                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.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);
        }

Same methods

EncodingNLS::GetBytes ( char chars, int charCount, byte bytes, int byteCount ) : int
EncodingNLS::GetBytes ( char chars, int charCount, byte bytes, int byteCount, EncoderNLS encoder ) : int
EncodingNLS::GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex ) : 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