Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.AttributeSyntax
Summary
Instructs the XmlEssentials source generator to generate source code for serializing and deserializing instances of the specified type and the types in its object graph. This class cannot be inherited.Usage
Apply[XmlSerializable] to a partial class that derives from XmlSerializerContext, once for each type you pass to the serializer. The source generator reads the attributes at compile time and adds a matching XmlTypeInfo<T> property to the class.
Order also covers the OrderLine type of its Lines property, and the context gets an OrderLine property too.
The generated property is named after the type. Set TypeInfoPropertyName to choose another name, for example when two listed types have the same name in different namespaces:
JsonSerializableAttribute in System.Text.Json.
Remarks
Place the attribute on a partial class that derives from XmlSerializerContext. The type is a type argument, so the compiler checks it and it may be any closed type, an array or a collection included. This attribute is analogous toJsonSerializableAttribute in System.Text.Json, which takes the type as a constructor
argument.
Type Parameters
T- The type to generate source code for.
Examples
Considerations
- The class must be
partialand derive fromXmlSerializerContext. Otherwise the generator reportsXMLESS001. GenerationModeoverrides the mode of the context for the listed type. A value other thanDefaultapplies to the type the attribute lists. A type listed withDefault, and a type the generator reaches from a listed type, takes the mode from[XmlSourceGenerationOptions]on the context.- Metadata and a write fast path are generated only for object types. For an enumeration, a collection, or a dictionary you list, such as
List<Order>, the property returns type info that the runtime library creates from the type arguments the generator names, with no reflection. For a simple value you list, such asint, the property returns the built-in type info. - A listed type is checked at compile time. See Understand the diagnostics for the errors the generator reports.
- The attribute does nothing at run time. The reflection resolver doesn’t read it.
Constructors
.ctor
Syntax
.ctor Inherited
Inherited from
System.AttributeSyntax
.ctor Inherited
Inherited from
objectSyntax
Properties
GenerationMode
Gets or sets the mode that indicates what the source generator generates for the type.Syntax
Property Value
Type:CloudNimble.Text.Xml.Serialization.XmlSourceGenerationMode
A bitwise combination of the enumeration values that specifies what is generated for the type. The default is
XmlSourceGenerationMode.Default.
Remarks
A value other than XmlSourceGenerationMode.Default overrides the XmlSourceGenerationOptionsAttribute.GenerationMode of the context for this type. The types reached from it take the mode of the context.Type
Gets the type to generate source code for.Syntax
Property Value
Type:System.Type
The type that the context can serialize and deserialize, which is T.
TypeId Inherited Virtual
Inherited from
System.AttributeSyntax
Property Value
Type:object
TypeInfoPropertyName
Gets or sets the name of the property for the generatedXmlTypeInfo1` for the type on the generated,
derived XmlSerializerContext type.
Syntax
Property Value
Type:string?
The name of the generated property. If the value is null or empty, the name is made from the
name of the type and the names of its type arguments. The default is null.
Methods
Equals Override
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttribute Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute?
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetCustomAttributes Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:System.Attribute[]
GetHashCode Override
Inherited from
System.AttributeSyntax
Returns
Type:int
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
IsDefaultAttribute Inherited Virtual
Inherited from
System.AttributeSyntax
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
IsDefined Inherited
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
Match Inherited Virtual
Inherited from
System.AttributeSyntax
Parameters
Returns
Type:bool
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.XmlSerializerContext
- CloudNimble.Text.Xml.Serialization.XmlSourceGenerationOptionsAttribute
- CloudNimble.Text.Xml.Serialization.XmlSourceGenerationMode
- CloudNimble.Text.Xml.Serialization.XmlTypeInfo