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)
 Class managing a script expression. More...
 
 Expression (string Script, string Source)
 Class managing a script expression. More...
 
 Expression (string Script, object Tag)
 Class managing a script expression. More...
 
 Expression (string Script, string Source, object Tag)
 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 bool IsNullOrVoid (object Result)
 Checks if a result object value is equal to null or void (i.e. its type equal to System.Threading.Tasks.VoidTaskResult). More...
 
static bool IsVoid (Type ResultType)
 Checks if a result object type is equal to void (i.e. its type equal to System.Threading.Tasks.VoidTaskResult). 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 EncodeString (string s)
 Converts a string value to a parsable expression string. More...
 
static string ToString (object Value)
 Converts an object to a string, that can be parsed as part of an expression. More...
 
static string ToString (string Value)
 Converts an object to a string, that can be parsed as part of an expression. More...
 
static string ToExpressionString (object Value)
 Converts an object to a string, that can be parsed as part of an expression. 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 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. Information loss is not accepted in type conversions. 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, bool AcceptInformationLoss, out object Result)
 Tries to convert an object Value to an object of type DesiredType . More...
 
static bool TryConvert (object Value, Type DesiredType, double WeightThreshold, out object Result)
 Tries to convert an object Value to an object of type DesiredType . More...
 
static bool TryConvert (IElement Value, Type DesiredType, bool AcceptInformationLoss, out IElement Result)
 Tries to convert an element Value to an element whose associated object is of type DesiredType . More...
 
static bool TryConvert (IElement Value, Type DesiredType, double WeightThreshold, 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 40 of file Expression.cs.

Constructor & Destructor Documentation

◆ Expression() [1/4]

Waher.Script.Expression.Expression ( string  Script)

Class managing a script expression.

Parameters
ScriptScript expression.

Definition at line 63 of file Expression.cs.

◆ Expression() [2/4]

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

Class managing a script expression.

Parameters
ScriptScript expression.
SourceSource of script.

Definition at line 73 of file Expression.cs.

◆ Expression() [3/4]

Waher.Script.Expression.Expression ( string  Script,
object  Tag 
)

Class managing a script expression.

Parameters
ScriptScript expression.
TagThis property allows the caller to tag the expression with an arbitrary object.

Definition at line 84 of file Expression.cs.

◆ Expression() [4/4]

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

Class managing a script expression.

Parameters
ScriptScript expression.
SourceSource of script.
TagThis property allows the caller to tag the expression with an arbitrary object.

Definition at line 96 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 5385 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 5397 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 5241 of file Expression.cs.

◆ EncodeString()

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

Converts a string value to a parsable expression string.

Parameters
sValue
Returns
Expression representation of string.

Definition at line 4986 of file Expression.cs.

◆ Equals()

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

Definition at line 4499 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 5923 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 5935 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 5946 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 5957 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 4423 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 4461 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 5456 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 5468 of file Expression.cs.

◆ GetHashCode()

override int Waher.Script.Expression.GetHashCode ( )

Definition at line 4508 of file Expression.cs.

◆ IsNullOrVoid()

static bool Waher.Script.Expression.IsNullOrVoid ( object  Result)
static

Checks if a result object value is equal to null or void (i.e. its type equal to System.Threading.Tasks.VoidTaskResult).

Parameters
ResultResult object.
Returns
If value is null or void.

Definition at line 4721 of file Expression.cs.

◆ IsVoid()

static bool Waher.Script.Expression.IsVoid ( Type  ResultType)
static

Checks if a result object type is equal to void (i.e. its type equal to System.Threading.Tasks.VoidTaskResult).

Parameters
ResultTypeResult type.
Returns
If type is void.

Definition at line 4735 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 4523 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 5228 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 5169 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 5110 of file Expression.cs.

◆ ToExpressionString()

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

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

Parameters
ValueValue
Returns
Expression string representation of value.

Definition at line 5052 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 4823 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 4833 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 4813 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 4871 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 4899 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 4770 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 4760 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 4843 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 4970 of file Expression.cs.

◆ ToString() [10/12]

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

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

Parameters
ValueValue
Returns
Expression string representation of value.

Definition at line 5031 of file Expression.cs.

◆ ToString() [11/12]

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

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

Parameters
ValueValue
Returns
Expression string representation of value.

Definition at line 5042 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 4941 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 4581 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 4596 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 4652 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 4666 of file Expression.cs.

◆ TryConvert() [1/4]

static bool Waher.Script.Expression.TryConvert ( IElement  Value,
Type  DesiredType,
bool  AcceptInformationLoss,
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.
AcceptInformationLossIf information loss is acceptable in the conversion.
ResultConversion result, if successful.
Returns
If conversion was successful.

Definition at line 5722 of file Expression.cs.

◆ TryConvert() [2/4]

static bool Waher.Script.Expression.TryConvert ( IElement  Value,
Type  DesiredType,
double  WeightThreshold,
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.
WeightThresholdMinimum weight threshold for acceptance of conversion. 1 = no loss acceptable, 0 = loss of everything acceptable.
ResultConversion result, if successful.
Returns
If conversion was successful.

Definition at line 5738 of file Expression.cs.

◆ TryConvert() [3/4]

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

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

Parameters
ValueValue to convert.
DesiredTypeDesired type.
AcceptInformationLossIf information loss is acceptable in the conversion.
ResultConverted object value, if successful.
Returns
If conversion was successful.

Definition at line 5530 of file Expression.cs.

◆ TryConvert() [4/4]

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

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

Parameters
ValueValue to convert.
DesiredTypeDesired type.
WeightThresholdMinimum weight threshold for acceptance of conversion. 1 = no loss acceptable, 0 = loss of everything acceptable.
ResultConverted object value, if successful.
Returns
If conversion was successful.

Definition at line 5545 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 5501 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 3382 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 5771 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 4803 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 4781 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 4792 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. Information loss is not accepted in type conversions.

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 5327 of file Expression.cs.

Property Documentation

◆ ContainsImplicitPrint

bool Waher.Script.Expression.ContainsImplicitPrint
get

If the expression contains implicit print operations.

Definition at line 4516 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 4414 of file Expression.cs.

◆ Root

ScriptNode Waher.Script.Expression.Root
get

Root script node.

Definition at line 4496 of file Expression.cs.

◆ Script

string Waher.Script.Expression.Script
get

Original script string.

Definition at line 207 of file Expression.cs.

◆ Source

string Waher.Script.Expression.Source
get

Source of script, or null if not defined.

Definition at line 212 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 5442 of file Expression.cs.


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