-
-
Notifications
You must be signed in to change notification settings - Fork 109
Write your Expression
Huajiang Wei edited this page Nov 5, 2021
·
1 revision
Expression has four property and function, which be realized in your own type.
- ReturnType: return type of expression, like number, bool, string
- Descriptor: display component of expression
- Type: name of expression
- ExecuteImpl: function of expression execution, which will be call when running the expression
- TextItemDescriptor - Text
- ExpressionDescriptor - Expression, where use can put other expression.
- ParameterDescriptor - parameter of function, which can be dragged to other location of expression.
- VariableDeclarationDescription - variable which can be dragged to other location
- StringInputDesciptor - string input in TextBox
- MultiLineStringInputDesciptor - multi line string input in TextBox
- SelectionItemDescriptor - selection in ComboBox
- ImageItemDescriptor - display a image
operator ! is not expression of logical expression. This expression has an boolean argument, and the return type is boolean.
public class NotExpression : Expression
{
public Expression Argument { get; set; }
public override string ReturnType
{
get { return "boolean"; }
}
public override Descriptor Descriptor
{
get
{
Descriptor desc = new Descriptor();
desc.Add(new TextItemDescriptor(this, "! ", true));
desc.Add(new ExpressionDescriptor(this, "Argument", "boolean") { IsOnlyNumberAllowed = false });
return desc;
}
}
public override string Type
{
get { return "UnaryExpression"; }
}
protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
{
if (Argument == null)
return Completion.Exception(Properties.Language.NullException, this);
var a = Argument.Execute(enviroment);
if (a.Type != CompletionType.Value || !(a.ReturnValue is bool))
return new Completion(Properties.Language.NotBoolean, CompletionType.Exception);
return new Completion(!(bool)a.ReturnValue);
}
}After adding to toolbar, the script editor can recognize this expression and its function
