mirror of
https://github.com/bitwarden/server.git
synced 2026-02-08 18:03:11 +08:00
24 lines
704 B
C#
24 lines
704 B
C#
|
|
using System.Text.RegularExpressions;
|
|||
|
|
|
|||
|
|
namespace Bit.Core.AdminConsole.Utilities;
|
|||
|
|
|
|||
|
|
public static partial class IntegrationTemplateProcessor
|
|||
|
|
{
|
|||
|
|
[GeneratedRegex(@"#(\w+)#")]
|
|||
|
|
private static partial Regex TokenRegex();
|
|||
|
|
|
|||
|
|
public static string ReplaceTokens(string template, object values)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(template) || values == null)
|
|||
|
|
return template;
|
|||
|
|
|
|||
|
|
var type = values.GetType();
|
|||
|
|
return TokenRegex().Replace(template, match =>
|
|||
|
|
{
|
|||
|
|
var propertyName = match.Groups[1].Value;
|
|||
|
|
var property = type.GetProperty(propertyName);
|
|||
|
|
return property?.GetValue(values)?.ToString() ?? match.Value;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|