Table of Contents

ConverterAttribute Class

Definition

Namespace
Bodu.Text.Serialization
Assembly
Bodu.Text.Serialization.dll
Package
Bodu.Text.Serialization 1.0.0
Source
ConverterAttribute.cs

Specifies the converter to use for a property, field, or type, taking precedence over the converters configured on the serializer options.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class ConverterAttribute : SerializationAttribute
Inheritance
ConverterAttribute
Attributes
System.AttributeUsageAttribute
Inherited Members
Extension Methods

Examples

public sealed class Package
{
    [Converter(typeof(VersionConverter))]
    public Version Version { get; set; } = new(1, 2, 3);
}

// VersionConverter governs the member.

Remarks

The referenced type must derive from the serializer's converter base type and declare a public parameterless constructor. Applied to a member, the converter governs that member only; applied to a type, it governs every use of the type.

Constructors

ConverterAttribute(Type)

Initializes a new instance of the ConverterAttribute class.

public ConverterAttribute(Type converterType)

Parameters

converterType Type

The converter type to use.

Exceptions

ArgumentNullException

Thrown when converterType is null.

Properties

ConverterType

Gets the converter type to use.

public Type ConverterType { get; }

Property Value

Type

The converter type.

Applies to

ProductVersions
.NET8, 10