public object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
{
events.sender = this;
try
{
if (_primitiveType != null)
{
if (encodingStyle != null && encodingStyle.Length > 0)
{
throw new InvalidOperationException(SR.Format(SR.XmlInvalidEncodingNotEncoded1, encodingStyle));
}
return DeserializePrimitive(xmlReader, events);
}
#if !NET_NATIVE
else if (Mode == SerializationMode.ReflectionOnly)
{
XmlMapping mapping;
if (_mapping != null && _mapping.GenerateSerializer)
{
mapping = _mapping;
}
else
{
XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
}
var reader = new ReflectionXmlSerializationReader(mapping, xmlReader, events, encodingStyle);
return reader.ReadObject();
}
else if (_tempAssembly == null || _typedSerializer)
{
XmlSerializationReader reader = CreateReader();
reader.Init(xmlReader, events, encodingStyle, _tempAssembly);
try
{
return Deserialize(reader);
}
finally
{
reader.Dispose();
}
}
else
{
return _tempAssembly.InvokeReader(_mapping, xmlReader, events, encodingStyle);
}
#else
else
{
if (this.innerSerializer != null)
{
if (!string.IsNullOrEmpty(this.DefaultNamespace))
{
this.innerSerializer.DefaultNamespace = this.DefaultNamespace;
}
XmlSerializationReader reader = this.innerSerializer.CreateReader();
reader.Init(xmlReader, encodingStyle);
try
{
return this.innerSerializer.Deserialize(reader);
}
finally
{
reader.Dispose();
}
}
else if (ReflectionMethodEnabled)
{
XmlMapping mapping;
if (_mapping != null && _mapping.GenerateSerializer)
{
mapping = _mapping;
}
else
{
XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
}
var reader = new ReflectionXmlSerializationReader(mapping, xmlReader, events, encodingStyle);
return reader.ReadObject();
}
else
{
throw new InvalidOperationException(SR.Format(SR.Xml_MissingSerializationCodeException, this.rootType, typeof(XmlSerializer).Name));
}
}
#endif
}
catch (Exception e)
{
if (e is TargetInvocationException)
e = e.InnerException;
if (xmlReader is IXmlLineInfo)
{
IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
throw new InvalidOperationException(SR.Format(SR.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), e);
}
else
{
throw new InvalidOperationException(SR.XmlSerializeError, e);
}
}
}