-
Notifications
You must be signed in to change notification settings - Fork 1
/
Query.cs
44 lines (36 loc) · 1.08 KB
/
Query.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
using System.Text.RegularExpressions;
namespace Conductor.Models.Entities;
public class Query : Entity
{
public int ConnectorId { get; set; }
public string Value { get; set; }
public bool Interpolated { get; set; }
public Connector Connector { get; set; }
public string Interpolate(string props)
{
string result = Value;
if (props.Contains('/'))
{
foreach (var prop in props.Split('/'))
{
if (prop.Contains(':'))
result = Interpolate(result, prop);
}
}
else if (props.Contains(':'))
result = Interpolate(result, props);
return result;
}
static string Interpolate(string script, string prop) =>
script.Replace(
$"{{{{{prop.Split(':')[0]}}}}}",
prop.Split(':')[1]
);
static bool IsInterpolated(string value) =>
Regex.IsMatch(value, @"{{.*}}");
public override void Complete()
{
Interpolated = IsInterpolated(Value);
base.Complete();
}
}