Skip to content
Miroiu Emanuel edited this page Oct 12, 2022 · 2 revisions

MathExpr Class

Namespace: StringMath

Assembly: StringMath

Inheritance: ObjectMathExpr

References: IMathContext, MathExprExtensions, Precedence

A mathematical expression.

public class MathExpr

Constructors

MathExpr(String)

Constructs a MathExpr from a string.

public MathExpr(string text);

Parameters

text String: The math expression.

MathExpr(String, IMathContext)

Constructs a MathExpr from an expression tree.

public MathExpr(string text, IMathContext context);

Parameters

text String

context IMathContext: The IMathContext in which this expression is evaluated.

Properties

Context

The IMathContext in which this expression is evaluated.

public IMathContext Context { get; set; }

Property Value

IMathContext

Item

public double Item { get; set; }

Property Value

Double

LocalVariables

A collection of variable names excluding globals from MathExpr.Variables.

public IReadOnlyCollection<String> LocalVariables { get; set; }

Property Value

IReadOnlyCollection

Result

The result of the expression.

public double Result { get; set; }

Property Value

Double

Text

Creates a string representation of the current expression.

public string Text { get; set; }

Property Value

String

Variables

A collection of variable names including globals extracted from the MathExpr.Text.

public IReadOnlyCollection<String> Variables { get; set; }

Property Value

IReadOnlyCollection

Methods

AddOperator(String, Func<Double, Double, Double>, Precedence?)

Add a new unary operator or overwrite an existing operator implementation. Precedence is always Precedence.Prefix.

public static void AddOperator(string name, Func<Double, Double, Double> operation, Precedence? precedence = null);

Parameters

name String: The operator's string representation.

operation Func<Double, Double, Double>: The operation to execute for this operator.

precedence Precedence?

AddOperator(String, Func<Double, Double>)

public static void AddOperator(string name, Func<Double, Double> operation);

Parameters

name String

operation Func<Double, Double>

AddVariable(String, Double)

public static void AddVariable(string name, double value);

Parameters

name String

value Double

Compile()

Compiles a MathExpr into a delegate.

public Func<Double> Compile();

Returns

Func: A type safe delegate.

Compile(String)

public Func<Double, Double> Compile(string var);

Parameters

var String

Returns

Func<Double, Double>

Compile(String, String)

public Func<Double, Double, Double> Compile(string var1, string var2);

Parameters

var1 String

var2 String

Returns

Func<Double, Double, Double>

Compile(String, String, String)

public Func<Double, Double, Double, Double> Compile(string var1, string var2, string var3);

Parameters

var1 String

var2 String

var3 String

Returns

Func<Double, Double, Double, Double>

Compile(String, String, String, String)

public Func<Double, Double, Double, Double, Double> Compile(string var1, string var2, string var3, string var4);

Parameters

var1 String

var2 String

var3 String

var4 String

Returns

Func<Double, Double, Double, Double, Double>

Compile(String, String, String, String, String)

public Func<Double, Double, Double, Double, Double, Double> Compile(string var1, string var2, string var3, string var4, string var5);

Parameters

var1 String

var2 String

var3 String

var4 String

var5 String

Returns

Func<Double, Double, Double, Double, Double, Double>

SetOperator(String, Func<Double, Double, Double>, Precedence?)

Add a new unary operator or overwrite an existing operator implementation. Precedence is always Precedence.Prefix.

public MathExpr SetOperator(string name, Func<Double, Double, Double> operation, Precedence? precedence = null);

Parameters

name String: The operator's string representation.

operation Func<Double, Double, Double>: The operation to execute for this operator.

precedence Precedence?

Returns

MathExpr: The current math expression.

SetOperator(String, Func<Double, Double>)

public MathExpr SetOperator(string name, Func<Double, Double> operation);

Parameters

name String

operation Func<Double, Double>

Returns

MathExpr

Substitute(String, Double)

Substitutes the variable with the given value.

public MathExpr Substitute(string name, double value);

Parameters

name String: The name of the variable.

value Double: The new value.

Returns

MathExpr

ToString()

public override string ToString();

Returns

String

Clone this wiki locally