Class MutationBase<TState>
Base class for mutation implementations that want sensible defaults for common behavior.
Implements
Inherited Members
Namespace: ModularityKit.Mutator.Abstractions.Engine
Assembly: ModularityKit.Mutator.dll
Syntax
public abstract class MutationBase<TState> : IMutation<TState>
Type Parameters
| Name | Description |
|---|---|
| TState | The type of state the mutation operates on. |
Remarks
Inheriting from MutationBase<TState> removes repeated boilerplate for:
- storing Intent and Context
- defaulting Validate(TState) to success
- defaulting Simulate(TState) to Apply(TState)
- building common MutationIntent instances
The base class is optional. Mutations can still implement IMutation<TState> directly when they need a different shape.
Constructors
| Edit this page View SourceMutationBase(MutationIntent, MutationContext)
Initializes a new mutation base with the provided intent and context.
Declaration
protected MutationBase(MutationIntent intent, MutationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| MutationIntent | intent | The mutation intent. |
| MutationContext | context | The execution context. |
Properties
| Edit this page View SourceContext
Gets the execution context containing metadata about who, when, why, and how the mutation is executed.
Declaration
public MutationContext Context { get; }
Property Value
| Type | Description |
|---|---|
| MutationContext |
Intent
Gets the intent describing this mutation — what change is being performed and why.
Declaration
public MutationIntent Intent { get; }
Property Value
| Type | Description |
|---|---|
| MutationIntent |
Methods
| Edit this page View SourceApply(TState)
Applies the mutation to the given state and returns the result.
Declaration
public abstract MutationResult<TState> Apply(TState state)
Parameters
| Type | Name | Description |
|---|---|---|
| TState | state | The current state to mutate. |
Returns
| Type | Description |
|---|---|
| MutationResult<TState> | A MutationResult<TState> containing the new state and any side-effects or logs. |
CreateIntent(string, string, string?, MutationRiskLevel, bool, BlastRadius?, IReadOnlySet<string>?, IReadOnlyDictionary<string, object>?)
Creates a common MutationIntent instance.
Declaration
protected static MutationIntent CreateIntent(string operationName, string category, string? description = null, MutationRiskLevel riskLevel = MutationRiskLevel.Low, bool isReversible = true, BlastRadius? estimatedBlastRadius = null, IReadOnlySet<string>? tags = null, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | operationName | The operation name. |
| string | category | The mutation category. |
| string | description | Optional human-readable description. |
| MutationRiskLevel | riskLevel | The mutation risk level. |
| bool | isReversible | Whether the mutation can be reversed. |
| BlastRadius | estimatedBlastRadius | Optional blast radius estimate. |
| IReadOnlySet<string> | tags | Optional classification tags. |
| IReadOnlyDictionary<string, object> | metadata | Optional metadata attached to the intent. |
Returns
| Type | Description |
|---|---|
| MutationIntent | A configured MutationIntent. |
Simulate(TState)
Simulates the mutation without changing the actual state (dry-run). Useful for testing, previewing effects, or computing potential side-effects.
Declaration
public virtual MutationResult<TState> Simulate(TState state)
Parameters
| Type | Name | Description |
|---|---|---|
| TState | state | The current state to simulate the mutation on. |
Returns
| Type | Description |
|---|---|
| MutationResult<TState> | A MutationResult<TState> reflecting the hypothetical outcome. |
Success(TState, StateChange, IReadOnlyList<SideEffect>?)
Creates a successful mutation result from a single state change.
Declaration
protected static MutationResult<TState> Success(TState newState, StateChange change, IReadOnlyList<SideEffect>? sideEffects = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TState | newState | The new state after the mutation. |
| StateChange | change | The single change applied. |
| IReadOnlyList<SideEffect> | sideEffects | Optional list of side effects. |
Returns
| Type | Description |
|---|---|
| MutationResult<TState> | A MutationResult<TState> representing success. |
Validate(TState)
Validates the mutation without applying it to ensure legality and preconditions.
Declaration
public virtual ValidationResult Validate(TState state)
Parameters
| Type | Name | Description |
|---|---|---|
| TState | state | The state against which validation should be performed. |
Returns
| Type | Description |
|---|---|
| ValidationResult | A ValidationResult indicating whether the mutation is valid and any violations. |