forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Executable.cs
49 lines (42 loc) · 1.19 KB
/
Executable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace BlocklyNet.Core.Model;
/// <summary>
/// Represents something executable.
/// </summary>
public abstract class Executable : IFragment
{
/// <summary>
/// Unique name of the executable.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// Block to calculate the value of the executable.
/// </summary>
public required Block? Block { get; set; }
/// <summary>
/// Use the block to evaluate the value.
/// </summary>
/// <param name="context">Current execution context.</param>
/// <returns>The value.</returns>
public Task<object?> EvaluateAsync(Context context)
{
/* See if script should be terminated. */
context.Cancellation.ThrowIfCancellationRequested();
/* If there is no block the result will always be null. */
if (Block == null)
return Task.FromResult((object?)null);
/* Use the block to get the current value. */
return Block.EvaluateAsync(context);
}
}
/// <summary>
/// Represents a single value.
/// </summary>
public class Value : Executable
{
}
/// <summary>
/// Represents a statement.
/// </summary>
public class Statement : Executable
{
}