RequiredAttribute Class
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
- Source
- RequiredAttribute.cs
Marks a property or field as required, so deserialization fails when the corresponding key is absent from the input.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false)]
public sealed class RequiredAttribute : SerializationAttribute
- Inheritance
-
RequiredAttribute
- Attributes
-
System.AttributeUsageAttribute
- Inherited Members
- Extension Methods
Examples
public sealed class ServerConfig
{
[Required]
public string Host { get; set; } = string.Empty;
}
// Deserializing input without a "Host" key throws a serialization exception.
Remarks
Applying this attribute has the same effect as declaring the member with the required keyword: the member must appear in the input being read, otherwise the serializer throws a serialization exception.
Constructors
RequiredAttribute()
Initializes a new instance of the RequiredAttribute class.
public RequiredAttribute()
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |