Table of Contents

Class PropertyBinder<T>

Namespace
PopcorningGuineaPig.Engine.Scenes
Assembly
PopcorningGuineaPig.Engine.dll

Fluent typed setter map for game-defined UI elements that want the Option B path (no reflection, strongly typed dispatch). Built on top of a Dictionary<TKey, TValue> of property-name → typed setter so each TrySet(object, string, object) call is a single hashtable lookup plus a delegate invocation.

Usage:

public sealed class MyWidget : InteractiveUIElement
{
    public static readonly IPropertyBinder Binder =
        new PropertyBinder<MyWidget>()
            .Add("text", (w, v) => w.Text = (string)v)
            .Add("score", (w, v) => w.Score = Convert.ToInt32(v));
    public string Text { get; set; } = string.Empty;
    public int Score { get; set; }
}

// At startup:
UIElementBinderRegistry.Register(typeof(MyWidget), MyWidget.Binder);

The PGPSCN JsonElement values that arrive at TrySet(object, string, object) after System.Text.Json deserialization are converted to the expected CLR type by UnwrapValue(object) (called by the registry before dispatch), so setters receive already-unwrapped CLR primitives (string, int, double, bool).

public sealed class PropertyBinder<T> : IPropertyBinder where T : class

Type Parameters

T
Inheritance
PropertyBinder<T>
Implements
Inherited Members

Methods

Add(string, Action<T, object>)

Register a setter for propertyName. The setter receives the target element (already cast to T) and the PGPSCN value. Returns this so calls can chain.

public PropertyBinder<T> Add(string propertyName, Action<T, object> setter)

Parameters

propertyName string
setter Action<T, object>

Returns

PropertyBinder<T>

TrySet(object, string, object)

Set propertyName on element to value. Returns true if the property was recognized and a write was attempted; false if the property name is unknown to this binder (the caller logs / no-ops).

public bool TrySet(object element, string propertyName, object value)

Parameters

element object
propertyName string
value object

Returns

bool