System.Xml.XmlBufferReader.TryEnsureBytes C# (CSharp) Méthode

TryEnsureBytes() private méthode

private TryEnsureBytes ( int count ) : bool
count int
Résultat bool
        private bool TryEnsureBytes(int count)
        {
            if (_stream == null)
                return false;
            DiagnosticUtility.DebugAssert(_offset <= int.MaxValue - count, "");
            int newOffsetMax = _offset + count;
            if (newOffsetMax < _offsetMax)
                return true;
            DiagnosticUtility.DebugAssert(newOffsetMax <= _windowOffsetMax, "");
            if (newOffsetMax > _buffer.Length)
            {
                byte[] newBuffer = new byte[Math.Max(newOffsetMax, _buffer.Length * 2)];
                System.Buffer.BlockCopy(_buffer, 0, newBuffer, 0, _offsetMax);
                _buffer = newBuffer;
                _streamBuffer = newBuffer;
            }
            int needed = newOffsetMax - _offsetMax;
            while (needed > 0)
            {
                int actual = _stream.Read(_buffer, _offsetMax, needed);
                if (actual == 0)
                    return false;
                _offsetMax += actual;
                needed -= actual;
            }
            return true;
        }