Table of Contents

PropertyNameAttribute Class

Definition

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

Specifies the key used for a property or field when it is serialized, overriding the member's CLR name and any configured naming policy.

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

Examples

public sealed class Profile
{
    [PropertyName("display-name")]
    public string DisplayName { get; set; } = "Ada";
}

// Serializes under the key "display-name".

Constructors

PropertyNameAttribute(string)

Initializes a new instance of the PropertyNameAttribute class.

public PropertyNameAttribute(string name)

Parameters

name string

The name to use for the member in serialized output.

Exceptions

ArgumentNullException

Thrown when name is null.

Properties

Name

Gets the name used for the member in serialized output.

public string Name { get; }

Property Value

string

The serialized member name.

Applies to

ProductVersions
.NET8, 10