Every cell operator inherits from fitSharp.Fit.Operators.CellOperator. There are five different types of operator interfaces we can implement, each controlling a different aspect of cell behavior:
- CompareOperator determines how cell contents are compared to a value.
- ComposeOperator constructs a new cell from a value.
- ExecuteOperator performs basic cell operations that fixtures may invoke.
- ParseOperator converts cell contents into a value.
- RuntimeOperator invokes constructors and methods using cells as parameters.
using fitSharp.Fit.Operators; using fitSharp.Machine.Engine; public class ParsePi: CellOperator, ParseOperator<Cell> {The CanParse method override determines which cells are processed by our operator. We check for "pi" in the cell and also that we are working with a numeric type. This preserves normal behavior if we're using "pi" as a string input or expected value.
public bool CanParse(Type type, TypedValue instance, Tree<Cell> parameters) { return type == typeof(double) && parameters.Value.Text == "pi"; }Overriding the Parse method changes the behavior when the cell is parsed to create an input or an expected value.
public TypedValue Parse(Type type, TypedValue instance, TreeTree<Cell> parameters) { return new TypedValue(System.Math.PI); } }