using System.Reflection;
using System.Text.Json;

namespace AyCode.Core.Serializers.Jsons;

/// <summary>
/// JSON-specific property accessor base class.
/// Adds JSON-specific encoding (JsonEncodedText for Utf8JsonWriter).
/// </summary>
public abstract class JsonPropertyAccessorBase : PropertyAccessorBase
{
    /// <summary>
    /// Pre-encoded property name for Utf8JsonWriter (STJ optimization).
    /// </summary>
    public JsonEncodedText JsonNameEncoded { get; }

    protected JsonPropertyAccessorBase(PropertyInfo prop, Type declaringType) 
        : base(prop, declaringType)
    {
        JsonNameEncoded = JsonEncodedText.Encode(prop.Name);
    }
}
