Add IsStringInternProperty to BinaryPropertyAccessorBase

Introduce IsStringInternProperty to cache the [AcStringIntern] attribute value for each property. Update the constructor to initialize this property, and revise class documentation to reflect the new addition. This enables efficient access to string interning settings per property.
This commit is contained in:
Loretta 2026-01-26 11:53:08 +01:00
parent ff73901ba8
commit 11ac2beb71
1 changed files with 14 additions and 2 deletions

View File

@ -7,7 +7,7 @@ namespace AyCode.Core.Serializers.Binaries;
/// <summary>
/// Binary-specific property accessor.
/// Inherits typed getters from PropertyAccessorBase.
/// Adds Binary-specific property: PropertyIndex.
/// Adds Binary-specific properties: PropertyIndex, IsStringInternProperty.
/// </summary>
public abstract class BinaryPropertyAccessorBase : PropertyAccessorBase
{
@ -18,14 +18,26 @@ public abstract class BinaryPropertyAccessorBase : PropertyAccessorBase
/// </summary>
public int PropertyIndex { get; internal set; } = -1;
/// <summary>
/// Cached string intern attribute value for this property.
/// null = no attribute (use global StringInterningMode setting)
/// true = [AcStringIntern(true)] - always intern
/// false = [AcStringIntern(false)] - never intern
/// </summary>
public bool? IsStringInternProperty { get; }
/// <summary>
/// Object getter for property filter context.
/// </summary>
public Func<object, object?> DynamicGetter => _dynamicGetter;
protected BinaryPropertyAccessorBase(PropertyInfo prop, Type declaringType)
protected BinaryPropertyAccessorBase(PropertyInfo prop, Type declaringType)
: base(prop, declaringType)
{
// All typed getters are initialized in PropertyAccessorBase
// Cache string intern attribute (inherit: true to check base class properties)
var attr = prop.GetCustomAttribute<AcStringInternAttribute>(inherit: true);
IsStringInternProperty = attr?.Enabled;
}
}