CanReadContentAs() private method

private CanReadContentAs ( ) : bool
return bool
        internal int ReadContentAsBase64(byte[] buffer, int index, int count)
        {
            // check arguments
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            switch (_state)
            {
            case State.None:
                if (!_reader.CanReadContentAs())
                {
                    throw _reader.CreateReadContentAsException(nameof(ReadContentAsBase64));
                }
                if (!Init())
                {
                    return(0);
                }
                break;

            case State.InReadContent:
                // if we have a correct decoder, go read
                if (_decoder == _base64Decoder)
                {
                    // read more binary data
                    return(ReadContentAsBinary(buffer, index, count));
                }
                break;

            case State.InReadElementContent:
                throw new InvalidOperationException(SR.Xml_MixingBinaryContentMethods);

            default:
                Debug.Fail($"Unexpected state {_state}");
                return(0);
            }

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

            // setup base64 decoder
            InitBase64Decoder();

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

        internal int  ReadContentAsBase64(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("ReadContentAsBase64");
                }
                if (!Init())
                {
                    return(0);
                }
                break;

            case State.InReadContent:
                // if we have a correct decoder, go read
                if (decoder == base64Decoder)
                {
                    // 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 base64 decoder
            InitBase64Decoder();

            // read more binary data
            return(ReadContentAsBinary(buffer, index, count));
        }
Beispiel #3
0
 public virtual object ReadContentAsObject()
 {
     if (!XmlReader.CanReadContentAs(this.NodeType))
     {
         throw this.CreateReadContentAsException(nameof(ReadContentAsObject));
     }
     return((object)this.InternalReadContentAsString());
 }