NamingPolicyAttribute Class
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
- Source
- NamingPolicyAttribute.cs
Specifies the NamingPolicy applied to the annotated type's members, overriding the serializer-wide property naming policy for that type.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
public sealed class NamingPolicyAttribute : SerializationAttribute
- Inheritance
-
NamingPolicyAttribute
- Attributes
-
System.AttributeUsageAttribute
- Inherited Members
- Extension Methods
Examples
[NamingPolicy(KnownNamingPolicy.SnakeCaseLower)]
public sealed class RetryPolicy
{
public int MaxRetryCount { get; set; } = 5;
}
// Serializes under the key "max_retry_count".
Remarks
The policy is chosen from the KnownNamingPolicy values, each of which maps to a static singleton on NamingPolicy. A member that carries an explicit PropertyNameAttribute is unaffected, since that attribute always takes precedence over any naming policy.
Constructors
NamingPolicyAttribute(KnownNamingPolicy)
Initializes a new instance of the NamingPolicyAttribute class.
public NamingPolicyAttribute(KnownNamingPolicy namingPolicy)
Parameters
namingPolicyKnownNamingPolicyThe known naming policy applied to the annotated type's members.
Exceptions
- ArgumentOutOfRangeException
Thrown when
namingPolicyis not a defined KnownNamingPolicy value.
Properties
NamingPolicy
Gets the naming policy applied to the annotated type's members, or null when the attribute specifies Unspecified.
public NamingPolicy? NamingPolicy { get; }
Property Value
- NamingPolicy
The resolved naming policy, or null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |