System.Xml.XmlNodeReader.ReadElementContentAsBase64 C# (CSharp) Méthode

ReadElementContentAsBase64() public méthode

public ReadElementContentAsBase64 ( byte buffer, int index, int count ) : int
buffer byte
index int
count int
Résultat int
        public override int ReadElementContentAsBase64( byte[] buffer, int index, int count ) {
            if ( readState != ReadState.Interactive ) {
                return 0;
            }

            // init ReadContentAsBinaryHelper when called first time
            if ( !bInReadBinary ) {
                readBinaryHelper = ReadContentAsBinaryHelper.CreateOrReset( readBinaryHelper, this );
            }

            // turn off bInReadBinary in order to have a normal Read() behavior when called from readBinaryHelper
            bInReadBinary = false;

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

            // turn on bInReadBinary in again and return
            bInReadBinary = true;
            return readCount;
        }

Usage Example

        private MemoryStream readBase64AsStream(XmlNodeReader reader)
        {
            MemoryStream ms = new MemoryStream();

            byte[] buf = new byte[1024];
            int numRead = 0;
            do
            {
                //numRead = reader.ReadElementContentAsBase64(buf, 0, 1024);
                numRead = reader.ReadElementContentAsBase64(buf, 0, 1024);
                ms.Write(buf, 0, numRead);
            }
            while (numRead >= 1024);

            return ms;
        }