DataFieldOverride
Represents a single field-level override that modifies one field on a FactorableData instance via reflection. The base class stores a field name and boxed value; the generic subclass DataFieldOverride<TField> adds type-safe Inspector access.
Definition
Namespace: Paragon.Core.ScriptableFactory
Assembly: Paragon.dll
[Serializable]
public class DataFieldOverrideGeneric Variant
[Serializable]
public class DataFieldOverride<TField> : DataFieldOverrideInherits: DataFieldOverride
Remarks
DataFieldOverride is the atomic unit of the variant system. Each instance represents one field modification: "set field X to value Y". The Apply() method uses reflection (FieldInfo.SetValue) to write the override value onto a target object.
The generic variant DataFieldOverride<TField> adds a typed Value property decorated with [ShowInInspector], which Odin uses to render a type-appropriate editor in the Inspector. This is the default override type created by DataOverride.AddFieldOverride() when no custom overrider is specified via [Overridable].
Quick Lookup
Get the field name
fieldOverride.FieldName
Get the value (boxed)
fieldOverride.GetValue()
Set the value (boxed)
fieldOverride.SetValue(newValue)
Apply to a target
fieldOverride.Apply(targetObject)
Get typed value
typedOverride.Value (generic variant only)
Properties
FieldName
The name of the field this override targets.
Value (Generic Variant)
Type-safe accessor for the override value. Available only on DataFieldOverride<TField>.
Returns default(TField) if the stored value is not of type TField.
Constructor
DataFieldOverride
fieldName
string
Name of the field to override (must match the target class's field name)
value
object
The override value (boxed)
DataFieldOverride<TField>
fieldName
string
Name of the field to override
fieldValue
TField
The typed override value
Methods
GetValue
Returns the current override value as a boxed object.
SetValue
Sets the override value.
value
object
New override value
Apply
Applies this override to a target object by setting the named field via reflection.
target
object
The target object (typically a FactorableData instance)
Returns: The override value that was applied.
If the field is not found on the target object, the method silently skips the assignment (field lookup returns null).
GetField
Helper that retrieves the FieldInfo for a named field on the target object.
target
object
The object to inspect
fieldName
string
The field name to look up
Returns: The FieldInfo, or null if not found.
Uses GetType().GetField(fieldName) which searches public instance fields by default.
Extension Points
Apply (virtual)
Override Apply() to implement custom override logic beyond simple field assignment (e.g., list merging, conditional application, value transformation).
Subclasses can use GetField() to access the target's field and implement custom behavior.
Implementation Requirements
When creating a custom DataFieldOverride subclass:
MUST accept
(string fieldName, object fieldValue)constructor parameters (required byActivator.CreateInstanceinDataOverride)MUST call
base(fieldName, fieldValue)in the constructorSHOULD override
Apply()for custom logicSHOULD be marked with
[Serializable]for persistence
Common Pitfalls
Public fields only by default
GetField() uses GetType().GetField(fieldName) without binding flags, which only finds public instance fields. To override non-public fields, a custom overrider subclass with explicit binding flags is required.
Silent failure on missing field
Apply() silently skips the override if the field is not found (no exception, no log). This can happen if the field was renamed or removed from the FactorableData class.
See Also
DataOverride — container that manages a collection of
DataFieldOverrideinstancesOverridableAttribute — attribute that marks fields as override-eligible
Last updated