public virtual object ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
{
if (!CanReadContentAs())
{
throw CreateReadContentAsException(nameof(ReadContentAs));
}
string strContentValue = InternalReadContentAsString();
if (returnType == typeof(string))
{
return strContentValue;
}
else
{
try
{
return XmlUntypedStringConverter.Instance.FromString(strContentValue, returnType, (namespaceResolver == null ? this as IXmlNamespaceResolver : namespaceResolver));
}
catch (FormatException e)
{
throw new XmlException(SR.Xml_ReadContentAsFormatException, returnType.ToString(), e, this as IXmlLineInfo);
}
catch (InvalidCastException e)
{
throw new XmlException(SR.Xml_ReadContentAsFormatException, returnType.ToString(), e, this as IXmlLineInfo);
}
}
}