protected string ReadString(int maxStringContentLength)
{
if (this.ReadState != ReadState.Interactive)
return string.Empty;
if (this.NodeType != XmlNodeType.Element)
MoveToElement();
if (this.NodeType == XmlNodeType.Element)
{
if (this.IsEmptyElement)
return string.Empty;
if (!Read())
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidOperation)));
if (this.NodeType == XmlNodeType.EndElement)
return string.Empty;
}
StringBuilder sb = null;
string result = string.Empty;
while (IsTextNode(this.NodeType))
{
string value = this.Value;
if (result.Length == 0)
{
result = value;
}
else
{
if (sb == null)
sb = new StringBuilder(result);
if (sb.Length > maxStringContentLength - value.Length)
XmlExceptionHelper.ThrowMaxStringContentLengthExceeded(this, maxStringContentLength);
sb.Append(value);
}
if (!Read())
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidOperation)));
}
if (sb != null)
result = sb.ToString();
if (result.Length > maxStringContentLength)
XmlExceptionHelper.ThrowMaxStringContentLengthExceeded(this, maxStringContentLength);
return result;
}