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
namestringThe name to use for the member in serialized output.
Exceptions
- ArgumentNullException
Thrown when
nameis 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
| Product | Versions |
|---|---|
| .NET | 8, 10 |