mlaumcherb/Mlaumcherb.Client.Avalonia/классы/Пролетариат/ArgumentsWithPlaceholders.cs
2024-11-06 00:04:12 +05:00

32 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Mlaumcherb.Client.Avalonia.классы;
public class ArgumentsWithPlaceholders
{
protected List<string> _raw_args = new();
public IEnumerable<string> FillPlaceholders(Dictionary<string, string> values)
{
foreach (var _s in _raw_args)
{
string arg = _s;
int begin = arg.IndexOf("${", StringComparison.Ordinal);
while(begin != -1)
{
int keyBegin = begin + 2;
int end = arg.IndexOf('}', keyBegin);
if (end != -1)
{
var key = arg.Substring(keyBegin, end - keyBegin);
if (!values.TryGetValue(key, out var value))
throw new Exception($"can't find value for placeholder '{key}'");
arg = arg.Replace("${"+ key + "}", value);
}
if(end + 1 < arg.Length)
begin = arg.IndexOf("${", end + 1, StringComparison.Ordinal);
else break;
}
yield return arg;
}
}
}