Refactor: add SerializeTypeMetadataBase for serializers
Introduce SerializeTypeMetadataBase<TMetadata> as a new abstract base class for serializer type metadata, extending TypeMetadataBase. Update Binary, JSON, and Toon serializer metadata classes to inherit from this new base, enabling shared serializer-specific logic and improving code organization. No functional changes to serialization behavior.
This commit is contained in:
parent
63ab695a0b
commit
858d43b881
|
|
@ -9,7 +9,7 @@ namespace AyCode.Core.Serializers.Binaries;
|
|||
|
||||
public static partial class AcBinarySerializer
|
||||
{
|
||||
internal sealed class BinarySerializeTypeMetadata : TypeMetadataBase<BinarySerializeTypeMetadata>
|
||||
internal sealed class BinarySerializeTypeMetadata : SerializeTypeMetadataBase<BinarySerializeTypeMetadata>
|
||||
{
|
||||
public BinaryPropertyAccessor[] Properties { get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public static partial class AcJsonSerializer
|
|||
private static JsonSerializeTypeMetadata GetTypeMetadata(in Type type)
|
||||
=> JsonSerializeTypeMetadata.GetOrCreateMetadata(type, static t => new JsonSerializeTypeMetadata(t));
|
||||
|
||||
private sealed class JsonSerializeTypeMetadata : TypeMetadataBase<JsonSerializeTypeMetadata>
|
||||
private sealed class JsonSerializeTypeMetadata : SerializeTypeMetadataBase<JsonSerializeTypeMetadata>
|
||||
{
|
||||
public PropertyAccessor[] Properties { get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
using System.Reflection;
|
||||
|
||||
namespace AyCode.Core.Serializers;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for serializer type metadata.
|
||||
/// Extends TypeMetadataBase for serializer-specific functionality.
|
||||
/// Used by Binary, JSON, and Toon serializers.
|
||||
/// Generic version provides built-in ThreadLocal caching with zero ref parameter overhead.
|
||||
/// </summary>
|
||||
/// <typeparam name="TMetadata">The concrete metadata type (must inherit from this class).</typeparam>
|
||||
public abstract class SerializeTypeMetadataBase<TMetadata> : TypeMetadataBase<TMetadata>
|
||||
where TMetadata : SerializeTypeMetadataBase<TMetadata>
|
||||
{
|
||||
protected SerializeTypeMetadataBase(Type type, Func<PropertyInfo, bool> ignorePropertyFilter)
|
||||
: base(type, ignorePropertyFilter)
|
||||
{
|
||||
// Base class handles:
|
||||
// - ReadableProperties, WritableProperties
|
||||
// - IId detection (IsIId, IdType, IdAccessorType, GetIdInt32/64/Guid)
|
||||
// - CompiledConstructor
|
||||
// - HasComplexProperties, NeedsReferenceTracking flags (set by derived classes)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,9 +10,9 @@ public static partial class AcToonSerializer
|
|||
{
|
||||
/// <summary>
|
||||
/// Cached metadata for a type including properties, type name, and descriptions.
|
||||
/// Uses TypeMetadataBase infrastructure for shared caching across all serializers.
|
||||
/// Uses SerializeTypeMetadataBase infrastructure for shared caching across all serializers.
|
||||
/// </summary>
|
||||
private sealed class ToonSerializeTypeMetadata : TypeMetadataBase<ToonSerializeTypeMetadata>
|
||||
private sealed class ToonSerializeTypeMetadata : SerializeTypeMetadataBase<ToonSerializeTypeMetadata>
|
||||
{
|
||||
public string TypeName { get; }
|
||||
public string ShortTypeName { get; }
|
||||
|
|
@ -58,6 +58,7 @@ public static partial class AcToonSerializer
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Property accessor with compiled getter and cached navigation metadata.
|
||||
/// Extends PropertyAccessorBase for shared functionality and adds Toon-specific metadata.
|
||||
|
|
|
|||
Loading…
Reference in New Issue