41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
namespace AyCode.Core.Serializers;
|
|
|
|
/// <summary>
|
|
/// Represents a deserialize chain that allows multiple deserializations from the same parsed data.
|
|
/// Maintains reference identity for IId objects across chain operations.
|
|
/// Implements IDisposable - call Dispose() when done or use 'using' statement.
|
|
/// </summary>
|
|
public interface IDeserializeChain<T> : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// The first deserialized value.
|
|
/// </summary>
|
|
T? Value { get; }
|
|
|
|
/// <summary>
|
|
/// Deserialize to another type from the same data.
|
|
/// </summary>
|
|
TResult? ThenDeserialize<TResult>();
|
|
|
|
/// <summary>
|
|
/// Populate an existing object from the same data.
|
|
/// Returns this chain for fluent API.
|
|
/// </summary>
|
|
IDeserializeChain<T> ThenPopulate(object target);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Empty deserialize chain implementation for null/empty data.
|
|
/// </summary>
|
|
public sealed class EmptyDeserializeChain<T> : IDeserializeChain<T>
|
|
{
|
|
public static readonly IDeserializeChain<T> Instance = new EmptyDeserializeChain<T>();
|
|
|
|
private EmptyDeserializeChain() { }
|
|
|
|
public T? Value => default;
|
|
public TResult? ThenDeserialize<TResult>() => default;
|
|
public IDeserializeChain<T> ThenPopulate(object target) => this;
|
|
public void Dispose() { }
|
|
}
|