StringEnumMemberNameAttribute Class
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
Specifies the string name used for an individual enumeration member when the enumeration is serialized by name, overriding both the member's CLR name and any naming policy applied to the enumeration.
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class StringEnumMemberNameAttribute : SerializationAttribute
- Inheritance
-
StringEnumMemberNameAttribute
- Attributes
-
System.AttributeUsageAttribute
- Inherited Members
- Extension Methods
Examples
public enum Status
{
Active,
[StringEnumMemberName("on-hold")]
OnHold,
}
// Serialized by name, Status.OnHold is written as "on-hold".
Remarks
The attribute applies only when the enumeration is converted to a string holding its member name - for example through the by-name enum converter - and has no effect when the enumeration is written as an integer.
This attribute derives from SerializationAttribute so that it is discoverable alongside the rest of the serialization attribute family.
Constructors
StringEnumMemberNameAttribute(string)
Initializes a new instance of the StringEnumMemberNameAttribute class.
public StringEnumMemberNameAttribute(string name)
Parameters
namestringThe string name used for the annotated enumeration member in serialized output.
Exceptions
- ArgumentNullException
Thrown when
nameis null.
Properties
Name
Gets the string name used for the annotated enumeration member in serialized output.
public string Name { get; }
Property Value
- string
The serialized member name.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |