IOnSerializing Interface
Definition
- Namespace
- Bodu.Text.Serialization
- Assembly
- Bodu.Text.Serialization.dll
- Package
- Bodu.Text.Serialization 1.0.0
- Source
- IOnSerializing.cs
Defines a callback that the serializer invokes on a value immediately before its members are written, letting the value prepare its state for serialization.
public interface IOnSerializing
- Extension Methods
Examples
public sealed class Snapshot : IOnSerializing
{
public long SavedAt { get; set; }
void IOnSerializing.OnSerializing() =>
SavedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // stamped before members are written
}
Remarks
OnSerializing() is called after a non-null value has been selected for writing and before its members are emitted, so any mutation it performs is reflected in the output.
Methods
OnSerializing()
Called by the serializer before the value's members are written.
void OnSerializing()
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |