Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.SerializationSyntax
Summary
Defines the default, reflection-based XML contract resolver used by XmlSerializer. This class cannot be inherited.Usage
DefaultXmlTypeInfoResolver is the resolver behind every XmlSerializer call that passes only a value, or a value and options. It finds the converter for a type and wraps it in type info. For a class or struct, that converter is built by inspecting the type’s members and attributes with reflection.
You rarely name the class. An XmlSerializerOptions instance with no TypeInfoResolver is given the shared DefaultXmlTypeInfoResolver.Instance the first time an XmlSerializer method that takes options uses it:
Converters list of the options, then [XmlConverter] on the type, then the built-in converters. It returns null when none of them handles the type.
The class has no public constructor. Use Instance. It’s the counterpart of DefaultJsonTypeInfoResolver in System.Text.Json.
View the complete sample on GitHub
Remarks
The resolver builds type info from the converters of an XmlSerializerOptions instance: its XmlSerializerOptions.Converters, the XmlConverterAttribute on the type, and the built-in converters.Considerations
- It isn’t safe for trimming or Native AOT, and it says so. The resolver reads members with reflection and creates generic converter types at run time, so the class carries
RequiresUnreferencedCodeandRequiresDynamicCode: the compiler warns wherever a trimmed or Native AOT application names it. In such an application, use a source-generated context. See Publish with Native AOT. - Options get it only from members that need reflection. An options instance with no resolver is given this one by an
XmlSerializermethod that takes options, byXmlSerializerOptions.GetConverter, byMakeReadOnly(populateMissingResolver: true), and by the sharedDefault,Web,Strict, andBclinstances. ReadingTypeInfoResolveror callingGetTypeInfonever brings it in. - The first request for a type is the expensive one. It reflects over the type’s members and builds its converter, which costs many times what a later call costs. Create one
XmlSerializerOptionsinstance and reuse it, because the options cache what the resolver returns. - There are no modifiers.
DefaultJsonTypeInfoResolverin System.Text.Json lets you add modifiers that edit a contract. This class has none. Change a mapping with attributes, options, or a custom converter. - Generated contexts don’t use it. A source-generated context builds the type info of every type it lists from generated code, and takes a built-in value, an XML value,
object, and a type you supplied a converter for from converters that exist already. - It’s stateless and shared.
Instanceis safe to use from any thread. The caching is done by the options, not by the resolver.
Constructors
.ctor Inherited
Inherited from
objectSyntax
Properties
Instance
Gets the shared instance of the DefaultXmlTypeInfoResolver class.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.DefaultXmlTypeInfoResolver
The shared resolver.
Methods
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
GetTypeInfo
Syntax
Parameters
Returns
Type:CloudNimble.Text.Xml.Serialization.XmlTypeInfo?
Exceptions
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- CloudNimble.Text.Xml.Serialization.IXmlTypeInfoResolver
- CloudNimble.Text.Xml.Serialization.XmlSerializerContext
- CloudNimble.Text.Xml.Serialization.XmlTypeInfo
- CloudNimble.Text.Xml.Serialization.XmlConverter
- CloudNimble.Text.Xml.Serialization.XmlConverterAttribute
- CloudNimble.Text.Xml.XmlSerializerOptions
- CloudNimble.Text.Xml.XmlSerializer