AyCode.Core/AyCode.Core/Serializers/DeserializationContextBase.cs

53 lines
2.0 KiB
C#

using System.Runtime.CompilerServices;
namespace AyCode.Core.Serializers;
/// <summary>
/// Abstract base class for all deserialization contexts (Binary, JSON, Toon).
/// Provides common deserialization operations: Id lookup, object storage by Id.
/// Derived classes are sealed for JIT devirtualization (direct call speed).
/// </summary>
/// <typeparam name="TMetadata">The concrete metadata type for deserialization.</typeparam>
/// <typeparam name="TOptions">The concrete options type.</typeparam>
public abstract class DeserializationContextBase<TMetadata, TOptions> : AcSerializerContextBase<TMetadata, TOptions>
where TMetadata : TypeMetadataBase
where TOptions : AcSerializerOptions
{
#region Object Lookup by Id (to be implemented by derived sealed classes)
// Future: Abstract methods for object lookup/storage
// protected abstract object? GetByIdInt32Core(int id);
// protected abstract object? GetByIdInt64Core(long id);
// protected abstract object? GetByIdGuidCore(Guid id);
// protected abstract object GetOrStoreByIdInt32Core(int id, object newObj);
// protected abstract object GetOrStoreByIdInt64Core(long id, object newObj);
// protected abstract object GetOrStoreByIdGuidCore(Guid id, object newObj);
#endregion
#region Object Resolution (to be moved from AcSerializerContextBase)
// Future: Common lookup/storage logic
// public object? GetById(int id) { ... }
// public object? GetById(long id) { ... }
// public object? GetById(Guid id) { ... }
// public object GetOrStoreById(int id, object newObj) { ... }
// public object GetOrStoreById(long id, object newObj) { ... }
// public object GetOrStoreById(Guid id, object newObj) { ... }
#endregion
#region Reset
/// <summary>
/// Resets deserialization-specific state. Called by derived classes.
/// </summary>
public override void Reset(TOptions options)
{
base.Reset(options);
// Future: Reset deserialization-specific state
}
#endregion
}