Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Waher.Script.Expression Class Reference

Class managing a script expression. More...

Public Member Functions

 Expression (string Script, string Source)
 Class managing a script expression. More...
 
 Expression (string Script)
 Class managing a script expression. More...
 
object Evaluate (Variables Variables)
 Evaluates the expression, using the variables provided in the Variables collection. This method should be used for evaluating expressions in a synchronous (blocking) context. More...
 
async Task< object > EvaluateAsync (Variables Variables)
 Evaluates the expression, using the variables provided in the Variables collection. This method should be used for evaluating expressions in an asynchronous (non-blocking) context. More...
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
bool ReferencesImplicitPrint (Variables Variables)
 If the expression, or any function call references, contain implicit print operations. More...
 
bool ForAll (ScriptNodeEventHandler Callback, object State, bool DepthFirst)
 Calls the callback method for all script nodes defined for the expression. More...
 
bool ForAll (ScriptNodeEventHandler Callback, object State, SearchMethod Order)
 Calls the callback method for all script nodes defined for the expression. More...
 

Static Public Member Functions

static bool TryGetConstant (string Name, Variables Variables, out IElement ValueElement)
 Tries to get a constant value, given its name. More...
 
static string Transform (string s, string StartDelimiter, string StopDelimiter, Variables Variables)
 Transforms a string by executing embedded script. More...
 
static string Transform (string s, string StartDelimiter, string StopDelimiter, Variables Variables, string Source)
 Transforms a string by executing embedded script. More...
 
static Task< string > TransformAsync (string s, string StartDelimiter, string StopDelimiter, Variables Variables)
 Transforms a string by executing embedded script. More...
 
static async Task< string > TransformAsync (string s, string StartDelimiter, string StopDelimiter, Variables Variables, string Source)
 Transforms a string by executing embedded script. More...
 
static string ToString (double Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (decimal Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static bool TryParse (string s, out double Value)
 Tries to parse a double-precision floating-point value. More...
 
static bool TryParse (string s, out float Value)
 Tries to parse a single-precision floating-point value. More...
 
static bool TryParse (string s, out decimal Value)
 Tries to parse a decimal-precision floating-point value. More...
 
static string ToString (Complex Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (BigInteger Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (bool Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (double[] Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (Complex[] Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (DateTime Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (TimeSpan Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (Enum Value)
 Converts a value to a string, that can be parsed as part of an expression. More...
 
static string ToString (string s)
 Converts a string value to a parsable expression string. More...
 
static string ToString (object Value)
 Converts an object to a string. More...
 
static double ToDouble (object Object)
 Converts an object to a double value. More...
 
static decimal ToDecimal (object Object)
 Converts an object to a double value. More...
 
static Complex ToComplex (object Object)
 Converts an object to a complex value. More...
 
static IElement Encapsulate (object Value)
 Encapsulates an object. More...
 
static bool UpgradeSemiGroup (ref IElement E1, ref ISet Set1, ref IElement E2, ref ISet Set2)
 Upgrades elements if necessary, to a common semi-field, trying to make them compatible. More...
 
static bool UpgradeField (ref IElement E1, ref ISet Set1, ref IElement E2, ref ISet Set2)
 Upgrades elements if necessary, to a common field extension, trying to make them compatible. More...
 
static object ConvertTo (IElement Value, Type DesiredType, ScriptNode Node)
 Tries to conevert an element value to a desired type. More...
 
static object ConvertTo (object Obj, Type DesiredType, ScriptNode Node)
 Tries to conevert an object to a desired type. More...
 
static bool TryConvert< T > (object Value, out T Result)
 Tries to convert an object Value to an object of type T . More...
 
static bool TryConvert (object Value, Type DesiredType, out object Result)
 Tries to convert an object Value to an object of type DesiredType . More...
 
static bool TryConvert (IElement Value, Type DesiredType, out IElement Result)
 Tries to convert an element Value to an element whose associated object is of type DesiredType . More...
 
static bool TryGetTypeConverter (Type From, Type To, out ITypeConverter Converter)
 Tries to get a type converter, converting objects from type From to objects of type To . More...
 
static object Eval (string Script)
 Evaluates script, in string format. More...
 
static object Eval (string Script, Variables Variables)
 Evaluates script, in string format. More...
 
static Task< object > EvalAsync (string Script)
 Evaluates script, in string format. More...
 
static Task< object > EvalAsync (string Script, Variables Variables)
 Evaluates script, in string format. More...
 

Properties

string Script [get]
 Original script string. More...
 
string Source [get]
 Source of script, or null if not defined. More...
 
bool IsAsynchronous [get]
 If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluated using EvaluateAsync(Variables). More...
 
ScriptNode Root [get]
 Root script node. More...
 
bool ContainsImplicitPrint [get]
 If the expression contains implicit print operations. More...
 
object Tag [get, set]
 This property allows the caller to tag the expression with an arbitrary object. More...
 

Detailed Description

Class managing a script expression.

Definition at line 38 of file Expression.cs.

Constructor & Destructor Documentation

◆ Expression() [1/2]

Waher.Script.Expression.Expression ( string  Script,
string  Source 
)

Class managing a script expression.

Parameters
ScriptScript expression.
SourceSource of script.

Definition at line 62 of file Expression.cs.

◆ Expression() [2/2]

Waher.Script.Expression.Expression ( string  Script)

Class managing a script expression.

Parameters
ScriptScript expression.

Definition at line 72 of file Expression.cs.

Member Function Documentation

◆ ConvertTo() [1/2]

static object Waher.Script.Expression.ConvertTo ( IElement  Value,
Type  DesiredType,
ScriptNode  Node 
)
static

Tries to conevert an element value to a desired type.

Parameters
ValueElement value.
DesiredTypeDesired type.
NodeScript node making the request.
Returns
Converted value.

Definition at line 5127 of file Expression.cs.

◆ ConvertTo() [2/2]

static object Waher.Script.Expression.ConvertTo ( object  Obj,
Type  DesiredType,
ScriptNode  Node 
)
static

Tries to conevert an object to a desired type.

Parameters
ObjObject to convert.
DesiredTypeDesired type.
NodeScript node making the request.
Returns
Converted value.

Definition at line 5139 of file Expression.cs.

◆ Encapsulate()

static IElement Waher.Script.Expression.Encapsulate ( object  Value)
static

Encapsulates an object.

Parameters
ValueObject
Returns
Encapsulated object.

Definition at line 4955 of file Expression.cs.

◆ Equals()

override bool Waher.Script.Expression.Equals ( object  obj)

Definition at line 4302 of file Expression.cs.

◆ Eval() [1/2]

static object Waher.Script.Expression.Eval ( string  Script)
static

Evaluates script, in string format.

Parameters
ScriptScript to parse and evaluate.
Returns
Result

Definition at line 5465 of file Expression.cs.

◆ Eval() [2/2]

static object Waher.Script.Expression.Eval ( string  Script,
Variables  Variables 
)
static

Evaluates script, in string format.

Parameters
ScriptScript to parse and evaluate.
VariablesVariables
Returns
Result

Definition at line 5477 of file Expression.cs.

◆ EvalAsync() [1/2]

static Task< object > Waher.Script.Expression.EvalAsync ( string  Script)
static

Evaluates script, in string format.

Parameters
ScriptScript to parse and evaluate.
Returns
Result

Definition at line 5488 of file Expression.cs.

◆ EvalAsync() [2/2]

static Task< object > Waher.Script.Expression.EvalAsync ( string  Script,
Variables  Variables 
)
static

Evaluates script, in string format.

Parameters
ScriptScript to parse and evaluate.
VariablesVariables
Returns
Result

Definition at line 5499 of file Expression.cs.

◆ Evaluate()

object Waher.Script.Expression.Evaluate ( Variables  Variables)

Evaluates the expression, using the variables provided in the Variables collection. This method should be used for evaluating expressions in a synchronous (blocking) context.

Parameters
VariablesVariables collection.
Returns
Result.

Definition at line 4248 of file Expression.cs.

◆ EvaluateAsync()

async Task< object > Waher.Script.Expression.EvaluateAsync ( Variables  Variables)

Evaluates the expression, using the variables provided in the Variables collection. This method should be used for evaluating expressions in an asynchronous (non-blocking) context.

Parameters
VariablesVariables collection.
Returns
Result.

Definition at line 4275 of file Expression.cs.

◆ ForAll() [1/2]

bool Waher.Script.Expression.ForAll ( ScriptNodeEventHandler  Callback,
object  State,
bool  DepthFirst 
)

Calls the callback method for all script nodes defined for the expression.

Parameters
CallbackCallback method to call.
StateState object to pass on to the callback method.
DepthFirstIf calls are made depth first (true) or on each node and then its leaves (false).
Returns
If the process was completed.

Definition at line 5196 of file Expression.cs.

◆ ForAll() [2/2]

bool Waher.Script.Expression.ForAll ( ScriptNodeEventHandler  Callback,
object  State,
SearchMethod  Order 
)

Calls the callback method for all script nodes defined for the expression.

Parameters
CallbackCallback method to call.
StateState object to pass on to the callback method.
OrderOrder to traverse the nodes.
Returns
If the process was completed.

Definition at line 5208 of file Expression.cs.

◆ GetHashCode()

override int Waher.Script.Expression.GetHashCode ( )

Definition at line 4311 of file Expression.cs.

◆ ReferencesImplicitPrint()

bool Waher.Script.Expression.ReferencesImplicitPrint ( Variables  Variables)

If the expression, or any function call references, contain implicit print operations.

Parameters
VariablesVariables containing available function and lambda definitions.
Returns
If an implicit print operation was found.

Definition at line 4326 of file Expression.cs.

◆ ToComplex()

static Complex Waher.Script.Expression.ToComplex ( object  Object)
static

Converts an object to a complex value.

Parameters
ObjectObject.
Returns
Complex value.

Definition at line 4942 of file Expression.cs.

◆ ToDecimal()

static decimal Waher.Script.Expression.ToDecimal ( object  Object)
static

Converts an object to a double value.

Parameters
ObjectObject.
Returns
Double value.

Definition at line 4883 of file Expression.cs.

◆ ToDouble()

static double Waher.Script.Expression.ToDouble ( object  Object)
static

Converts an object to a double value.

Parameters
ObjectObject.
Returns
Double value.

Definition at line 4824 of file Expression.cs.

◆ ToString() [1/12]

static string Waher.Script.Expression.ToString ( BigInteger  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4559 of file Expression.cs.

◆ ToString() [2/12]

static string Waher.Script.Expression.ToString ( bool  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4569 of file Expression.cs.

◆ ToString() [3/12]

static string Waher.Script.Expression.ToString ( Complex  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4549 of file Expression.cs.

◆ ToString() [4/12]

static string Waher.Script.Expression.ToString ( Complex[]  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4607 of file Expression.cs.

◆ ToString() [5/12]

static string Waher.Script.Expression.ToString ( DateTime  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4635 of file Expression.cs.

◆ ToString() [6/12]

static string Waher.Script.Expression.ToString ( decimal  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4506 of file Expression.cs.

◆ ToString() [7/12]

static string Waher.Script.Expression.ToString ( double  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4496 of file Expression.cs.

◆ ToString() [8/12]

static string Waher.Script.Expression.ToString ( double[]  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4579 of file Expression.cs.

◆ ToString() [9/12]

static string Waher.Script.Expression.ToString ( Enum  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4706 of file Expression.cs.

◆ ToString() [10/12]

static string Waher.Script.Expression.ToString ( object  Value)
static

Converts an object to a string.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4766 of file Expression.cs.

◆ ToString() [11/12]

static string Waher.Script.Expression.ToString ( string  s)
static

Converts a string value to a parsable expression string.

Parameters
sValue
Returns
Expression representation of string.

Definition at line 4722 of file Expression.cs.

◆ ToString() [12/12]

static string Waher.Script.Expression.ToString ( TimeSpan  Value)
static

Converts a value to a string, that can be parsed as part of an expression.

Parameters
ValueValue
Returns
String representation of value.

Definition at line 4677 of file Expression.cs.

◆ Transform() [1/2]

static string Waher.Script.Expression.Transform ( string  s,
string  StartDelimiter,
string  StopDelimiter,
Variables  Variables 
)
static

Transforms a string by executing embedded script.

Parameters
sString to transform.
StartDelimiterStart delimiter.
StopDelimiterStop delimiter.
VariablesCollection of variables.
Returns
Transformed string.

Definition at line 4383 of file Expression.cs.

◆ Transform() [2/2]

static string Waher.Script.Expression.Transform ( string  s,
string  StartDelimiter,
string  StopDelimiter,
Variables  Variables,
string  Source 
)
static

Transforms a string by executing embedded script.

Parameters
sString to transform.
StartDelimiterStart delimiter.
StopDelimiterStop delimiter.
VariablesCollection of variables.
SourceOptional source of s .
Returns
Transformed string.

Definition at line 4398 of file Expression.cs.

◆ TransformAsync() [1/2]

static Task< string > Waher.Script.Expression.TransformAsync ( string  s,
string  StartDelimiter,
string  StopDelimiter,
Variables  Variables 
)
static

Transforms a string by executing embedded script.

Parameters
sString to transform.
StartDelimiterStart delimiter.
StopDelimiterStop delimiter.
VariablesCollection of variables.
Returns
Transformed string.

Definition at line 4441 of file Expression.cs.

◆ TransformAsync() [2/2]

static async Task< string > Waher.Script.Expression.TransformAsync ( string  s,
string  StartDelimiter,
string  StopDelimiter,
Variables  Variables,
string  Source 
)
static

Transforms a string by executing embedded script.

Parameters
sString to transform.
StartDelimiterStart delimiter.
StopDelimiterStop delimiter.
VariablesCollection of variables.
SourceOptional source of s .
Returns
Transformed string.

Definition at line 4455 of file Expression.cs.

◆ TryConvert() [1/2]

static bool Waher.Script.Expression.TryConvert ( IElement  Value,
Type  DesiredType,
out IElement  Result 
)
static

Tries to convert an element Value to an element whose associated object is of type DesiredType .

Parameters
ValueElement to convert.
DesiredTypeDesired type of associated object.
ResultConversion result.
Returns
If conversion was successful.

Definition at line 5305 of file Expression.cs.

◆ TryConvert() [2/2]

static bool Waher.Script.Expression.TryConvert ( object  Value,
Type  DesiredType,
out object  Result 
)
static

Tries to convert an object Value to an object of type DesiredType .

Parameters
ValueValue to convert.
DesiredTypeDesired type.
ResultConversion result.
Returns
If conversion was successful.

Definition at line 5268 of file Expression.cs.

◆ TryConvert< T >()

static bool Waher.Script.Expression.TryConvert< T > ( object  Value,
out T  Result 
)
static

Tries to convert an object Value to an object of type T .

Template Parameters
TDesired type.
Parameters
ValueValue to convert.
ResultConversion result.
Returns
If conversion was successful.

Definition at line 5241 of file Expression.cs.

◆ TryGetConstant()

static bool Waher.Script.Expression.TryGetConstant ( string  Name,
Variables  Variables,
out IElement  ValueElement 
)
static

Tries to get a constant value, given its name.

Parameters
NameName
VariablesCurrent set of variables. Can be null.
ValueElementIf found, constant value will be placed here.
Returns
If a constant with the given name was found.

Definition at line 3307 of file Expression.cs.

◆ TryGetTypeConverter()

static bool Waher.Script.Expression.TryGetTypeConverter ( Type  From,
Type  To,
out ITypeConverter  Converter 
)
static

Tries to get a type converter, converting objects from type From to objects of type To .

Parameters
FromStart type.
ToDesired type.
ConverterType Converter found, or null if not found.
Returns
If a type converter could be found, or constructed from existing converters.

Definition at line 5336 of file Expression.cs.

◆ TryParse() [1/3]

static bool Waher.Script.Expression.TryParse ( string  s,
out decimal  Value 
)
static

Tries to parse a decimal-precision floating-point value.

Parameters
sString-representation
ValueParsed value.
Returns
If parsing was successful.

Definition at line 4539 of file Expression.cs.

◆ TryParse() [2/3]

static bool Waher.Script.Expression.TryParse ( string  s,
out double  Value 
)
static

Tries to parse a double-precision floating-point value.

Parameters
sString-representation
ValueParsed value.
Returns
If parsing was successful.

Definition at line 4517 of file Expression.cs.

◆ TryParse() [3/3]

static bool Waher.Script.Expression.TryParse ( string  s,
out float  Value 
)
static

Tries to parse a single-precision floating-point value.

Parameters
sString-representation
ValueParsed value.
Returns
If parsing was successful.

Definition at line 4528 of file Expression.cs.

◆ UpgradeField()

static bool Waher.Script.Expression.UpgradeField ( ref IElement  E1,
ref ISet  Set1,
ref IElement  E2,
ref ISet  Set2 
)
static

Upgrades elements if necessary, to a common field extension, trying to make them compatible.

Parameters
E1Element 1.
Set1Set containing element 1.
E2Element 2.
Set2Set containing element 2.
Returns
If elements have been upgraded to become compatible.

Definition at line 5070 of file Expression.cs.

◆ UpgradeSemiGroup()

static bool Waher.Script.Expression.UpgradeSemiGroup ( ref IElement  E1,
ref ISet  Set1,
ref IElement  E2,
ref ISet  Set2 
)
static

Upgrades elements if necessary, to a common semi-field, trying to make them compatible.

Parameters
E1Element 1.
Set1Set containing element 1.
E2Element 2.
Set2Set containing element 2.
Returns
If elements have been upgraded to become compatible.

Definition at line 5040 of file Expression.cs.

Property Documentation

◆ ContainsImplicitPrint

bool Waher.Script.Expression.ContainsImplicitPrint
get

If the expression contains implicit print operations.

Definition at line 4319 of file Expression.cs.

◆ IsAsynchronous

bool Waher.Script.Expression.IsAsynchronous
get

If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluated using EvaluateAsync(Variables).

Definition at line 4239 of file Expression.cs.

◆ Root

ScriptNode Waher.Script.Expression.Root
get

Root script node.

Definition at line 4299 of file Expression.cs.

◆ Script

string Waher.Script.Expression.Script
get

Original script string.

Definition at line 181 of file Expression.cs.

◆ Source

string Waher.Script.Expression.Source
get

Source of script, or null if not defined.

Definition at line 186 of file Expression.cs.

◆ Tag

object Waher.Script.Expression.Tag
getset

This property allows the caller to tag the expression with an arbitrary object.

Definition at line 5182 of file Expression.cs.


The documentation for this class was generated from the following file: