Table of Contents

Class Result

Namespace
xFunc.Maths.Results
Assembly
xFunc.Maths.dll

Represents the result of expression evaluation.

public abstract class Result
Inheritance
Result
Derived
Inherited Members

Examples

Get result by using the TryGetNumber(out NumberValue?) method:

var processor = new Processor();
var result = processor.Solve("2 + 2");
if (result.TryGetNumber(out var number))
    Console.WriteLine(number); // outputs '4'

Get result by using the Number property:

var processor = new Processor();
var result = processor.Solve("2 + 2");

var number = result.Number; // equals '4'

Get result by using the ToString() implementation:

var processor = new Processor();
var result = processor.Solve("2 + 2");

Console.WriteLine(result); // outputs '4'

Get result by using the pattern matching:

var processor = new Processor();
var result = processor.Solve("2 + 2");
if (result is Result.NumberResult numberResult)
    Console.WriteLine(numberResult.Number); // outputs '4'

Remarks

It is a hand-made implementation of the discriminated union. The Result class provides the abstraction (root class) for DU, whereas implementation for each possible return type is dedicated to the appropriate nested result class.

Properties

Angle

Gets the angle value.

public virtual AngleValue Angle { get; }

Property Value

AngleValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.AngleResult.

Area

Gets the area value.

public virtual AreaValue Area { get; }

Property Value

AreaValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.AreaResult.

Bool

Gets the boolean value.

public virtual bool Bool { get; }

Property Value

bool

Exceptions

InvalidCastException

Thrown when the current instance is not Result.BooleanResult.

ComplexNumber

Gets the complex number value.

public virtual Complex ComplexNumber { get; }

Property Value

Complex

Exceptions

InvalidCastException

Thrown when the current instance is not Result.ComplexNumberResult.

Lambda

Gets the lambda value.

public virtual Lambda Lambda { get; }

Property Value

Lambda

Exceptions

InvalidCastException

Thrown when the current instance is not Result.LambdaResult.

Length

Gets the length value.

public virtual LengthValue Length { get; }

Property Value

LengthValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.LengthResult.

Mass

Gets the mass value.

public virtual MassValue Mass { get; }

Property Value

MassValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.MassResult.

Matrix

Gets the matrix value.

public virtual MatrixValue Matrix { get; }

Property Value

MatrixValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.MatrixResult.

Number

Gets the number value.

public virtual NumberValue Number { get; }

Property Value

NumberValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.NumberResult.

Power

Gets the power value.

public virtual PowerValue Power { get; }

Property Value

PowerValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.PowerResult.

Rational

Gets the rational value.

public virtual RationalValue Rational { get; }

Property Value

RationalValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.RationalResult.

String

Gets the string value.

public virtual string String { get; }

Property Value

string

Exceptions

InvalidCastException

Thrown when the current instance is not Result.StringResult.

Temperature

Gets the temperature value.

public virtual TemperatureValue Temperature { get; }

Property Value

TemperatureValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.TemperatureResult.

Time

Gets the time value.

public virtual TimeValue Time { get; }

Property Value

TimeValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.TimeResult.

Vector

Gets the vector value.

public virtual VectorValue Vector { get; }

Property Value

VectorValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.VectorResult.

Volume

Gets the volume value.

public virtual VolumeValue Volume { get; }

Property Value

VolumeValue

Exceptions

InvalidCastException

Thrown when the current instance is not Result.VolumeResult.

Methods

Create(object)

Wraps the result of expression evaluation into Result.

public static Result Create(object result)

Parameters

result object

The result of expression evaluation.

Returns

Result

The result.

Exceptions

InvalidResultException

The type of result is not supported.

TryGetAngle(out AngleValue?)

Gets the angle value.

public bool TryGetAngle(out AngleValue? angleValue)

Parameters

angleValue AngleValue?

The angle value.

Returns

bool

true if the current instance contains AngleValue, otherwise false.

TryGetArea(out AreaValue?)

Gets the area value.

public bool TryGetArea(out AreaValue? areaValue)

Parameters

areaValue AreaValue?

The area value.

Returns

bool

true if the current instance contains AreaValue, otherwise false.

TryGetBoolean(out bool?)

Gets the boolean value.

public bool TryGetBoolean(out bool? boolValue)

Parameters

boolValue bool?

The boolean value.

Returns

bool

true if the current instance contains bool, otherwise false.

TryGetComplexNumber(out Complex?)

Gets the complex number.

public bool TryGetComplexNumber(out Complex? complexNumberValue)

Parameters

complexNumberValue Complex?

The complex number.

Returns

bool

true if the current instance contains Complex, otherwise false.

TryGetLambda(out Lambda?)

Gets the lambda.

public bool TryGetLambda(out Lambda? lambda)

Parameters

lambda Lambda?

The lambda.

Returns

bool

true if the current instance contains Lambda, otherwise false.

TryGetLength(out LengthValue?)

Gets the length value.

public bool TryGetLength(out LengthValue? lengthValue)

Parameters

lengthValue LengthValue?

The length value.

Returns

bool

true if the current instance contains LengthValue, otherwise false.

TryGetMass(out MassValue?)

Gets the mass value.

public bool TryGetMass(out MassValue? massValue)

Parameters

massValue MassValue?

The mass value.

Returns

bool

true if the current instance contains MassValue, otherwise false.

TryGetMatrix(out MatrixValue?)

Gets the matrix value.

public bool TryGetMatrix(out MatrixValue? matrixValue)

Parameters

matrixValue MatrixValue?

The matrix value.

Returns

bool

true if the current instance contains MatrixValue, otherwise false.

TryGetNumber(out NumberValue?)

Gets the number value.

public bool TryGetNumber(out NumberValue? number)

Parameters

number NumberValue?

The number value.

Returns

bool

true if the current instance contains NumberValue, otherwise false.

TryGetPower(out PowerValue?)

Gets the power value.

public bool TryGetPower(out PowerValue? powerValue)

Parameters

powerValue PowerValue?

The power value.

Returns

bool

true if the current instance contains PowerValue, otherwise false.

TryGetRational(out RationalValue?)

Gets the rational value.

public bool TryGetRational(out RationalValue? rationalValue)

Parameters

rationalValue RationalValue?

The rational value.

Returns

bool

true if the current instance contains RationalValue, otherwise false.

TryGetString(out string?)

Gets the string.

public bool TryGetString(out string? stringValue)

Parameters

stringValue string

The string value.

Returns

bool

true if the current instance contains string, otherwise false.

TryGetTemperature(out TemperatureValue?)

Gets the temperature value.

public bool TryGetTemperature(out TemperatureValue? temperatureValue)

Parameters

temperatureValue TemperatureValue?

The temperature value.

Returns

bool

true if the current instance contains TemperatureValue, otherwise false.

TryGetTime(out TimeValue?)

Gets the time value.

public bool TryGetTime(out TimeValue? timeValue)

Parameters

timeValue TimeValue?

The time value.

Returns

bool

true if the current instance contains TimeValue, otherwise false.

TryGetVector(out VectorValue?)

Gets the vector value.

public bool TryGetVector(out VectorValue? vectorValue)

Parameters

vectorValue VectorValue?

The vector value.

Returns

bool

true if the current instance contains VectorValue, otherwise false.

TryGetVolume(out VolumeValue?)

Gets the volume value.

public bool TryGetVolume(out VolumeValue? volumeValue)

Parameters

volumeValue VolumeValue?

The volume value.

Returns

bool

true if the current instance contains VolumeValue, otherwise false.

Operators

implicit operator Result(bool)

public static implicit operator Result(bool boolean)

Parameters

boolean bool

The boolean value.

Returns

Result

The boolean result.

implicit operator Result(Complex)

public static implicit operator Result(Complex complexNumber)

Parameters

complexNumber Complex

The complex number.

Returns

Result

The complex number result.

implicit operator Result(string)

public static implicit operator Result(string str)

Parameters

str string

The string.

Returns

Result

The string result.

implicit operator Result(Lambda)

public static implicit operator Result(Lambda lambda)

Parameters

lambda Lambda

The lambda.

Returns

Result

The lambda result.

implicit operator Result(MatrixValue)

public static implicit operator Result(MatrixValue matrix)

Parameters

matrix MatrixValue

The matrix value.

Returns

Result

The matrix result.

implicit operator Result(VectorValue)

public static implicit operator Result(VectorValue vector)

Parameters

vector VectorValue

The vector value.

Returns

Result

The vector result.

implicit operator Result(NumberValue)

public static implicit operator Result(NumberValue numberValue)

Parameters

numberValue NumberValue

The number value.

Returns

Result

The number result.

implicit operator Result(RationalValue)

public static implicit operator Result(RationalValue rational)

Parameters

rational RationalValue

The rational value.

Returns

Result

The rational result.

implicit operator Result(AngleValue)

public static implicit operator Result(AngleValue angle)

Parameters

angle AngleValue

The angle value.

Returns

Result

The angle result.

implicit operator Result(AreaValue)

public static implicit operator Result(AreaValue area)

Parameters

area AreaValue

The area value.

Returns

Result

The area result.

implicit operator Result(LengthValue)

public static implicit operator Result(LengthValue length)

Parameters

length LengthValue

The length value.

Returns

Result

The length result.

implicit operator Result(MassValue)

public static implicit operator Result(MassValue mass)

Parameters

mass MassValue

The mass value.

Returns

Result

The mass result.

implicit operator Result(PowerValue)

public static implicit operator Result(PowerValue power)

Parameters

power PowerValue

The power value.

Returns

Result

The power result.

implicit operator Result(TemperatureValue)

public static implicit operator Result(TemperatureValue temperature)

Parameters

temperature TemperatureValue

The temperature value.

Returns

Result

The temperature result.

implicit operator Result(TimeValue)

public static implicit operator Result(TimeValue time)

Parameters

time TimeValue

The time value.

Returns

Result

The time result.

implicit operator Result(VolumeValue)

public static implicit operator Result(VolumeValue volume)

Parameters

volume VolumeValue

The volume value.

Returns

Result

The volume result.

See Also