IncludeAttribute Class
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
- Source
- IncludeAttribute.cs
Forces a member to participate in serialization: a property's non-public accessors are bound (allowing members such
as { get; private set; } or { get; init; } with a non-public setter to be read and written), and a
public field is surfaced even when the serializer options' IncludeFields setting is disabled.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false)]
public sealed class IncludeAttribute : SerializationAttribute
- Inheritance
-
IncludeAttribute
- Attributes
-
System.AttributeUsageAttribute
- Inherited Members
- Extension Methods
Examples
public sealed class Counter
{
[Include]
public int Total { get; private set; }
[Include]
public int Retries;
}
// Both members round-trip, despite the non-public setter and the field.
Remarks
Without this attribute a property is included only when it exposes a public getter, and is assigned only through a
public setter; when the attribute is present the serializer binds through the declared accessors regardless of their
visibility. Public fields participate only when this attribute is applied or the serializer options'
IncludeFields setting is enabled; non-public fields are never surfaced.
Constructors
IncludeAttribute()
Initializes a new instance of the IncludeAttribute class.
public IncludeAttribute()
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |