FieldVariable
Sealed internal Variable implementation that reads and writes a field on an owner object via reflection. Used for variables discovered automatically from [Variable]-attributed fields on Action subclasses.
Definition
Namespace: Paragon.Core.ActionSystem Assembly: Paragon.dll
[Serializable]
internal sealed class FieldVariable : VariableInheritance: Variable → FieldVariable
Remarks
FieldVariable provides a live binding to an actual field on the owning Action instance. When GetValue() is called, it reads the field via FieldInfo.GetValue(); when SetValue() is called, it writes via FieldInfo.SetValue(). This means changes made directly to the action's field are immediately visible through the variable, and vice versa.
The FieldInfo is lazily resolved on first access via GetField(), which looks up the field by name using BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic. This lazy resolution handles deserialization scenarios where FieldInfo cannot be persisted.
Field variables are:
Created automatically during ActionVariables construction and after deserialization
Not removable — they are managed by the reflection discovery system
Stored in the
fieldVariablesdictionary ofActionVariables
Constructor
FieldVariable(object, FieldInfo)
Creates a field variable bound to a specific field on an owner object. The type and name are derived from the FieldInfo.
owner
object
The object instance that owns the field (typically an Action)
fieldInfo
FieldInfo
Reflection metadata for the target field
Methods
SetValue
Writes the value to the owner's field via reflection.
value
object
The value to assign to the field
GetValue
Reads the current value from the owner's field via reflection.
Returns: The current field value as object.
Common Pitfalls
FieldInfo is lazily resolved The FieldInfo reference is not serialized. It is re-resolved by name on first access after deserialization. If the field is renamed or removed from the action class, the lookup will return null and cause a NullReferenceException. The ActionVariables reconciliation system mitigates this by recreating variables for mismatched fields.
Live binding means dual access Because FieldVariable reads/writes the actual field, changes made by code that directly modifies the action's field are visible through the variable. This is by design — but it means the variable does not hold an independent copy. Be aware of this when debugging value changes.
See Also
Variable — abstract base class
DynamicVariable — the value-backed alternative
ActionVariables — the container that discovers and manages
FieldVariableinstancesVariable Subsystem — subfolder overview
Last updated