-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathExtensions.cs
More file actions
57 lines (49 loc) · 1.65 KB
/
Extensions.cs
File metadata and controls
57 lines (49 loc) · 1.65 KB
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
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Globalization;
using System.Text;
using Squidex.Infrastructure.Queries;
namespace Squidex.Providers.MySql;
internal static class Extensions
{
public static StringBuilder AppendJsonPath(this StringBuilder sb, PropertyPath path)
{
sb.Append('`');
sb.Append(path[0]);
sb.Append("`, ");
sb.AppendJsonPropertyPath(path);
return sb;
}
public static StringBuilder AppendJsonPropertyPath(this StringBuilder sb, PropertyPath path)
{
sb.Append("\'$");
foreach (var property in path.Skip(1))
{
if (int.TryParse(property, NumberStyles.Integer, CultureInfo.InvariantCulture, out var index))
{
sb.Append(CultureInfo.InvariantCulture, $"[{index}]");
}
else
{
sb.Append('.');
sb.Append('"');
sb.Append(property);
sb.Append('"');
}
}
sb.Append('\'');
return sb;
}
public static string JsonSubPath(this PropertyPath path)
{
return new StringBuilder().AppendJsonPropertyPath(path).ToString();
}
public static string JsonPath(this PropertyPath path)
{
return new StringBuilder().AppendJsonPath(path).ToString();
}
}