forked from devcat-studio/VSCodeLuaDebug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cs
More file actions
44 lines (39 loc) · 1.53 KB
/
Copy pathUtilities.cs
File metadata and controls
44 lines (39 loc) · 1.53 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
// Original work by:
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Modified by:
/*---------------------------------------------------------------------------------------------
* Copyright (c) NEXON Korea Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Text.RegularExpressions;
using System.Reflection;
namespace VSCodeDebug
{
public class Utilities
{
private static readonly Regex VARIABLE = new Regex(@"\{(\w+)\}");
public static string ExpandVariables(string format, dynamic variables, bool underscoredOnly = true)
{
if (variables == null) {
variables = new { };
}
Type type = variables.GetType();
return VARIABLE.Replace(format, match => {
string name = match.Groups[1].Value;
if (!underscoredOnly || name.StartsWith("_")) {
PropertyInfo property = type.GetProperty(name);
if (property != null) {
object value = property.GetValue(variables, null);
return value.ToString();
}
return '{' + name + ": not found}";
}
return match.Groups[0].Value;
});
}
}
}