microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1b74b19bc12c226dcd0f3fcd4eab6d66babbc2a8

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/cadl-vs/src/VariableResolver.cs

24lines · modecode

1using System.Collections.Generic;
2using System.Text.RegularExpressions;
3
4namespace Microsoft.Cadl.VisualStudio
5{
6 internal static class VariableResolver
7 {
8 private const string VARIABLE_REGEXP = @"\$\{(.*?)\}";
9
10 public static string ResolveVariables(string value, IDictionary<string, string> variables)
11 {
12 return Regex.Replace(value, VARIABLE_REGEXP, (match) =>
13 {
14 var group = match.Groups[1];
15 if (group != null && variables.TryGetValue(group.Value, out var variable))
16 {
17 return variable;
18 }
19 return match.Value;
20 });
21 }
22 }
23}
24
25