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));
}