Skip to main content
Table of Contents

Class PropertyAccessorCache

Namespace
Stratara.Shared.Reflections
Assembly
Stratara.Shared.dll

Process-wide cache of compiled property-getter and -setter delegates plus their PropertyInfo. Avoids the per-call overhead of reflection on hot paths such as the merge primitives, event-mapper factory, and aggregate field-change application.

public static class PropertyAccessorCache
Inheritance
PropertyAccessorCache
Inherited Members

Remarks

All cache stores are unbounded. The framework assumes a finite set of (Type, PropertyName) pairs per process.

Methods

GetOrCreateGetter<T, TProp>(string)

Returns a cached or freshly-compiled getter delegate for the named property on T.

public static Func<T, TProp> GetOrCreateGetter<T, TProp>(string propertyName)

Parameters

propertyName string

Name of the public instance property.

Returns

Func<T, TProp>

A strongly-typed getter delegate.

Type Parameters

T

Type that declares the property.

TProp

CLR type of the property's value.

Exceptions

ArgumentException

Thrown when the property is not found on T.

GetOrCreateSetter<T, TProp>(string)

Returns a cached or freshly-compiled setter delegate for the named property on T.

public static Action<T, TProp> GetOrCreateSetter<T, TProp>(string propertyName)

Parameters

propertyName string

Name of the public instance property.

Returns

Action<T, TProp>

A strongly-typed setter delegate.

Type Parameters

T

Type that declares the property.

TProp

CLR type of the property's value.

Exceptions

ArgumentException

Thrown when the property is not found on T.

GetValueByName<TTarget, TProperty>(TTarget, string)

Reads the named property from target using the cached strongly-typed getter.

public static TProperty GetValueByName<TTarget, TProperty>(TTarget target, string propertyName)

Parameters

target TTarget

Instance to read.

propertyName string

Name of the public instance property.

Returns

TProperty

The current property value.

Type Parameters

TTarget

Type that declares the property.

TProperty

CLR type of the property's value.

SetValueByName<TTarget>(TTarget, string, object?)

Untyped-value overload of SetValueByName<TTarget, TProperty>(TTarget, string, TProperty): the property type is resolved from the cached PropertyInfo and the typed setter is then invoked via reflection. Used when the caller only knows the property name (e.g. apply-handler for generic FieldChangedEvent).

public static void SetValueByName<TTarget>(TTarget target, string propertyName, object? value)

Parameters

target TTarget

Instance to mutate.

propertyName string

Name of the public instance property.

value object

New property value, boxed as object.

Type Parameters

TTarget

Type that declares the property.

Exceptions

ArgumentException

Thrown when the property is not found on TTarget.

SetValueByName<TTarget, TProperty>(TTarget, string, TProperty)

Sets the named property on target using the cached strongly-typed setter for TTarget / TProperty.

public static void SetValueByName<TTarget, TProperty>(TTarget target, string propertyName, TProperty value)

Parameters

target TTarget

Instance to mutate.

propertyName string

Name of the public instance property.

value TProperty

New property value.

Type Parameters

TTarget

Type that declares the property.

TProperty

CLR type of the property's value.