Add CreateXmlReader overload - adds Type parameter (#13302)
* Add CreateXmlReader overload - adds Type parameter This change allows inheritors of XmlSerializerInputFormatter to return a different XmlReader depending on the type being serialized. For example, an inheritor could return XSD-validating readers that validate against one schema or another (or perhaps not validate at all), depending on the value of the type parameter.
This commit is contained in:
parent
5c05b9288a
commit
8b861ea7d7
|
|
@ -47,6 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
protected override bool CanReadType(System.Type type) { throw null; }
|
protected override bool CanReadType(System.Type type) { throw null; }
|
||||||
protected virtual System.Xml.Serialization.XmlSerializer CreateSerializer(System.Type type) { throw null; }
|
protected virtual System.Xml.Serialization.XmlSerializer CreateSerializer(System.Type type) { throw null; }
|
||||||
protected virtual System.Xml.XmlReader CreateXmlReader(System.IO.Stream readStream, System.Text.Encoding encoding) { throw null; }
|
protected virtual System.Xml.XmlReader CreateXmlReader(System.IO.Stream readStream, System.Text.Encoding encoding) { throw null; }
|
||||||
|
protected virtual System.Xml.XmlReader CreateXmlReader(System.IO.Stream readStream, System.Text.Encoding encoding, System.Type type) { throw null; }
|
||||||
protected virtual System.Xml.Serialization.XmlSerializer GetCachedSerializer(System.Type type) { throw null; }
|
protected virtual System.Xml.Serialization.XmlSerializer GetCachedSerializer(System.Type type) { throw null; }
|
||||||
protected virtual System.Type GetSerializableType(System.Type declaredType) { throw null; }
|
protected virtual System.Type GetSerializableType(System.Type declaredType) { throw null; }
|
||||||
[System.Diagnostics.DebuggerStepThroughAttribute]
|
[System.Diagnostics.DebuggerStepThroughAttribute]
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var xmlReader = CreateXmlReader(readStream, encoding);
|
var type = GetSerializableType(context.ModelType);
|
||||||
var type = GetSerializableType(context.ModelType);
|
using var xmlReader = CreateXmlReader(readStream, encoding, type);
|
||||||
|
|
||||||
var serializer = GetCachedSerializer(type);
|
var serializer = GetCachedSerializer(type);
|
||||||
|
|
||||||
|
|
@ -191,6 +191,18 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
return wrapperProvider?.WrappingType ?? declaredType;
|
return wrapperProvider?.WrappingType ?? declaredType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called during deserialization to get the <see cref="XmlReader"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="readStream">The <see cref="Stream"/> from which to read.</param>
|
||||||
|
/// <param name="encoding">The <see cref="Encoding"/> used to read the stream.</param>
|
||||||
|
/// <param name="type">The <see cref="Type"/> that is to be deserialized.</param>
|
||||||
|
/// <returns>The <see cref="XmlReader"/> used during deserialization.</returns>
|
||||||
|
protected virtual XmlReader CreateXmlReader(Stream readStream, Encoding encoding, Type type)
|
||||||
|
{
|
||||||
|
return CreateXmlReader(readStream, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called during deserialization to get the <see cref="XmlReader"/>.
|
/// Called during deserialization to get the <see cref="XmlReader"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue