public override 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));
}
// if not the first call to ReadContentAsBase64
if (_parsingFunction == ParsingFunction.InReadElementContentAsBinary)
{
// and if we have a correct decoder
if (_incReadDecoder == _base64Decoder)
{
// read more binary data
return ReadElementContentAsBinary(buffer, index, count);
}
}
// first call of ReadElementContentAsBase64 -> initialize
else
{
if (_readState != ReadState.Interactive)
{
return 0;
}
if (_parsingFunction == ParsingFunction.InReadContentAsBinary)
{
throw new InvalidOperationException(SR.Xml_MixingBinaryContentMethods);
}
if (_curNode.type != XmlNodeType.Element)
{
throw CreateReadElementContentAsException(nameof(ReadElementContentAsBinHex));
}
if (!InitReadElementContentAsBinary())
{
return 0;
}
}
// setup base64 decoder
InitBase64Decoder();
// read binary data
return ReadElementContentAsBinary(buffer, index, count);
}