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 DataFieldOverride

Generic Variant

[Serializable]
public class DataFieldOverride<TField> : DataFieldOverride

Inherits: 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

Goal
How

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

Parameter
Type
Description

fieldName

string

Name of the field to override (must match the target class's field name)

value

object

The override value (boxed)

DataFieldOverride<TField>

Parameter
Type
Description

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.

Parameter
Type
Description

value

object

New override value

Apply

Applies this override to a target object by setting the named field via reflection.

Parameter
Type
Description

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.

Parameter
Type
Description

target

object

The object to inspect

fieldName

string

The field name to look up

Returns: The FieldInfo, or null if not found.

circle-info

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:

  1. MUST accept (string fieldName, object fieldValue) constructor parameters (required by Activator.CreateInstance in DataOverride)

  2. MUST call base(fieldName, fieldValue) in the constructor

  3. SHOULD override Apply() for custom logic

  4. SHOULD be marked with [Serializable] for persistence

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

Last updated