CreateReadElementContentAsException() private method

private CreateReadElementContentAsException ( string methodName ) : Exception
methodName string
return System.Exception
        internal int ReadElementContentAsBase64(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.NodeType != XmlNodeType.Element)
                {
                    throw _reader.CreateReadElementContentAsException(nameof(ReadElementContentAsBase64));
                }
                if (!InitOnElement())
                {
                    return(0);
                }
                break;

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

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

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

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

            // setup base64 decoder
            InitBase64Decoder();

            // read more binary data
            return(ReadElementContentAsBinary(buffer, index, count));
        }
        internal int  ReadElementContentAsBase64(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.NodeType != XmlNodeType.Element)
                {
                    throw reader.CreateReadElementContentAsException("ReadElementContentAsBase64");
                }
                if (!InitOnElement())
                {
                    return(0);
                }
                break;

            case State.InReadContent:
                throw new InvalidOperationException(Res.GetString(Res.Xml_MixingBinaryContentMethods));

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

            default:
                Debug.Assert(false);
                return(0);
            }

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

            // setup base64 decoder
            InitBase64Decoder();

            // read more binary data
            return(ReadElementContentAsBinary(buffer, index, count));
        }
Example #3
0
 internal Exception CreateReadElementContentAsException(string methodName)
 {
     return(XmlReader.CreateReadElementContentAsException(methodName, this.NodeType));
 }