System.Xml.ReadContentAsBinaryHelper.ReadContentAsBinHex C# (CSharp) Méthode

ReadContentAsBinHex() private méthode

private ReadContentAsBinHex ( byte buffer, int index, int count ) : int
buffer byte
index int
count int
Résultat int
        internal int ReadContentAsBinHex( byte[] buffer, int index, int count ) {
            // check arguments
            if ( buffer == null ) {
                throw new ArgumentNullException( "buffer" );
            }
            if ( count < 0 ) {
                throw new ArgumentOutOfRangeException( "count" );
            }
            if ( index < 0 ) {
                throw new ArgumentOutOfRangeException( "index" );
            }
            if ( buffer.Length - index < count ) {
                throw new ArgumentOutOfRangeException( "count" );
            }

            switch ( state ) {
                case State.None:
                    if ( !reader.CanReadContentAs() ) {
                        throw reader.CreateReadContentAsException( "ReadContentAsBinHex" );
                    }
                    if ( !Init() ) {
                        return 0;
                    }
                    break;
                case State.InReadContent:
                    // if we have a correct decoder, go read
                    if ( decoder == binHexDecoder ) {
                        // read more binary data
                        return ReadContentAsBinary( buffer, index, count );
                    }
                    break;
                case State.InReadElementContent:
                    throw new InvalidOperationException( Res.GetString( Res.Xml_MixingBinaryContentMethods ) );
                default:
                    Debug.Assert( false );
                    return 0;
            }    

            Debug.Assert( state == State.InReadContent );

            // setup binhex decoder
            InitBinHexDecoder();

            // read more binary data
            return ReadContentAsBinary( buffer, index, count );
        }

Usage Example

        public override int ReadContentAsBinHex( byte[] buffer, int index, int count ) {
            if ( ReadState != ReadState.Interactive ) {
                return 0;
            }

            if ( state != State.InReadBinary ) {
                // forward ReadBinHexChunk calls into the base (wrapped) reader if possible, i.e. if it can read chunks and we 
                // should not check characters
                if ( base.CanReadBinaryContent && ( !checkCharacters ) ) {
                    readBinaryHelper = null;
                    state = State.InReadBinary;
                    return base.ReadContentAsBinHex( buffer, index, count );
                }
                // the wrapped reader cannot read chunks or we are on an element where we should check characters or ignore white spaces
                else {
                    readBinaryHelper = ReadContentAsBinaryHelper.CreateOrReset( readBinaryHelper, this );
                }
            }
            else { 
                // forward calls into wrapped reader 
                if ( readBinaryHelper == null ) {
                    return base.ReadContentAsBinHex( buffer, index, count );
                }
            }

            // turn off InReadBinary state in order to have a normal Read() behavior when called from readBinaryHelper
            state = State.Interactive;

            // call to the helper
            int readCount = readBinaryHelper.ReadContentAsBinHex(buffer, index, count);

            // turn on InReadBinary in again and return
            state = State.InReadBinary;
            return readCount;        
        }
All Usage Examples Of System.Xml.ReadContentAsBinaryHelper::ReadContentAsBinHex