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
propertyNamestringName of the public instance property.
Returns
- Func<T, TProp>
A strongly-typed getter delegate.
Type Parameters
TType that declares the property.
TPropCLR 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
propertyNamestringName of the public instance property.
Returns
- Action<T, TProp>
A strongly-typed setter delegate.
Type Parameters
TType that declares the property.
TPropCLR 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
targetTTargetInstance to read.
propertyNamestringName of the public instance property.
Returns
- TProperty
The current property value.
Type Parameters
TTargetType that declares the property.
TPropertyCLR 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
targetTTargetInstance to mutate.
propertyNamestringName of the public instance property.
valueobjectNew property value, boxed as object.
Type Parameters
TTargetType 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
targetTTargetInstance to mutate.
propertyNamestringName of the public instance property.
valueTPropertyNew property value.
Type Parameters
TTargetType that declares the property.
TPropertyCLR type of the property's value.