-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDslExpression.cs
77 lines (63 loc) · 1.73 KB
/
DslExpression.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Diagnostics;
namespace MapboxMaui.Expressions;
[DebuggerDisplay("{GetString()}")]
public partial class DslExpression : List<object>
{
public DslOperator Operator { get; }
public DslExpression(DslOperator @operator)
{
Operator = @operator;
}
public DslExpression(DslOperator @operator, params object[] arguments)
: base(arguments)
{
Operator = @operator;
}
public DslExpression(params object[] arguments)
: base(arguments)
{
}
public object[] ToObjects()
{
var result = new List<object>();
if (!string.IsNullOrWhiteSpace(Operator.Value))
{
result.Add(Operator);
}
foreach (var argument in this)
{
switch (argument)
{
case DslExpression expression:
result.Add(expression.ToObjects());
break;
default:
result.Add(argument);
break;
}
}
return result.ToArray();
}
private string GetString()
{
var items = new List<string>();
if (!string.IsNullOrWhiteSpace(Operator.Value))
{
items.Add(Operator.Value);
}
foreach (var argument in this)
{
switch (argument)
{
case DslExpression expression:
items.Add(expression.ToString());
break;
default:
items.Add(argument.ToString());
break;
}
}
return $"[{string.Join(",", items)}]";
}
public static DslExpression Args(params object[] arguments) => new(arguments);
}