XmlSerializerOutputFormatter Class¶
Summary¶
This class handles serialization of objects to XML using [System.Xml.Serialization.XmlSerializer]()
Syntax¶
public class XmlSerializerOutputFormatter : OutputFormatter, IOutputFormatter, IApiResponseFormatMetadataProvider
Constructors¶
-
Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter.XmlSerializerOutputFormatter()
Initializes a new instance of [Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter](Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter.yml) with default XmlWriterSettings.
public XmlSerializerOutputFormatter()
-
XmlSerializerOutputFormatter
(System.Xml.XmlWriterSettings)¶ Initializes a new instance of [Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter](Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter.yml)
Arguments: - writerSettings (System.Xml.XmlWriterSettings) – The settings to be used by the [System.Xml.Serialization.XmlSerializer]().
public XmlSerializerOutputFormatter(XmlWriterSettings writerSettings)
-
Properties¶
-
WrapperProviderFactories
()¶ Gets the list of [Microsoft.AspNet.Mvc.Xml.IWrapperProviderFactory](Microsoft.AspNet.Mvc.Xml.IWrapperProviderFactory.yml) to provide the wrapping type for serialization.
Return type: System.Collections.Generic.IList{Microsoft.AspNet.Mvc.Xml.IWrapperProviderFactory} public IList<IWrapperProviderFactory> WrapperProviderFactories { get; }
-
WriterSettings
()¶ Gets the settings to be used by the XmlWriter.
Return type: System.Xml.XmlWriterSettings public XmlWriterSettings WriterSettings { get; }
-
Methods¶
-
CanWriteType
(System.Type, System.Type)¶ Arguments: - declaredType (System.Type) –
- runtimeType (System.Type) –
Return type: System.Boolean
protected override bool CanWriteType(Type declaredType, Type runtimeType)
-
CreateSerializer
(System.Type)¶ Create a new instance of [System.Xml.Serialization.XmlSerializer]() for the given object type.
Arguments: - type (System.Type) – The type of object for which the serializer should be created.
Return type: System.Xml.Serialization.XmlSerializer
Returns: A new instance of [System.Xml.Serialization.XmlSerializer]()
protected virtual XmlSerializer CreateSerializer(Type type)
-
CreateXmlWriter
(System.IO.Stream, System.Xml.XmlWriterSettings)¶ Creates a new instance of [System.Xml.XmlWriter]() using the given stream and the [Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter.WriterSettings](Microsoft.AspNet.Mvc.Xml.XmlSerializerOutputFormatter.yml).
Arguments: - writeStream (System.IO.Stream) – The stream on which the XmlWriter should operate on.
- xmlWriterSettings (System.Xml.XmlWriterSettings) –
Return type: System.Xml.XmlWriter
Returns: A new instance of [System.Xml.XmlWriter]()
public virtual XmlWriter CreateXmlWriter(Stream writeStream, XmlWriterSettings xmlWriterSettings)
-
GetCachedSerializer
(System.Type)¶ Gets the cached serializer or creates and caches the serializer for the given type.
Arguments: - type (System.Type) –
Return type: System.Xml.Serialization.XmlSerializer
Returns: The [System.Xml.Serialization.XmlSerializer]() instance.
protected virtual XmlSerializer GetCachedSerializer(Type type)
-
GetSerializableType
(System.Type)¶ Gets the type to be serialized.
Arguments: - type (System.Type) – The original type to be serialized
Return type: System.Type
Returns: The original or wrapped type provided by any [Microsoft.AspNet.Mvc.Xml.IWrapperProvider](Microsoft.AspNet.Mvc.Xml.IWrapperProvider.yml).
protected virtual Type GetSerializableType(Type type)
-
ResolveType
(System.Type, System.Type)¶ Gets the type of the object to be serialized.
Arguments: - declaredType (System.Type) – The declared type of the object.
- runtimeType (System.Type) – The runtime type of the object
Return type: System.Type
Returns: A type that needs to be serialized.
protected virtual Type ResolveType(Type declaredType, Type runtimeType)
-
WriteResponseBodyAsync
(Microsoft.AspNet.Mvc.OutputFormatterContext)¶ Arguments: - context (Microsoft.AspNet.Mvc.OutputFormatterContext) –
Return type: System.Threading.Tasks.Task
public override Task WriteResponseBodyAsync(OutputFormatterContext context)
-