Table of Contents

ConstructorAttribute Class

Definition

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

Marks the constructor the serializer uses to instantiate a type during deserialization, resolving the ambiguity when a type declares more than one constructor.

[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
public sealed class ConstructorAttribute : SerializationAttribute
Inheritance
ConstructorAttribute
Attributes
System.AttributeUsageAttribute
Inherited Members
Extension Methods

Examples

public sealed class Endpoint
{
    [Constructor]
    public Endpoint(string host, int port) => (Host, Port) = (host, port);

    public Endpoint(Uri uri) : this(uri.Host, uri.Port) { }

    public string Host { get; }
    public int Port { get; }
}

// Deserialization instantiates Endpoint through the marked constructor.

Remarks

When no constructor carries this attribute, the serializer uses a public parameterless constructor when one exists, otherwise the single declared constructor, otherwise the constructor with the most parameters.

Constructors

ConstructorAttribute()

public ConstructorAttribute()

Applies to

ProductVersions
.NET8, 10