-
-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Add methods to AtataContext, which are similar to FillTemplateString but additionally the variables are escaped for URI:
public string FillUriTemplateString(string template);
public string FillUriTemplateString(string template, IDictionary<string, object> additionalVariables);Fills the path template string with variables of the AtataContext instance. The template can contain variables wrapped with curly braces, e.g. "{varName}".
Variables support standard .NET formatting ("{numberVar:D5}" or "{dateTimeVar:yyyy-MM-dd}") and extended formatting for strings (for example, "{stringVar:/*}" appends "/" to the beginning of the string, if variable is not null). In order to output a { use {{, and to output a } use }}.
Variables are escaped by default using Uri.EscapeDataString(string) method. In order to not escape a variable, use :noescape modifier, for example "{stringVar:noescape}". To escape a variable using Uri.EscapeUriString(string) method, preserving special URI symbols, use :uriescape modifier, for example "{stringVar:uriescape}". Use :dataescape in complex scenarios (like adding optional query parameter) together with an extended formatting, for example "{stringVar:dataescape:?q=*}", to escape the value and prefix it with "?q=", but nothing will be output in case stringVar is null.
TemplateStringTransformer
Also add core method to TemplateStringTransformer:
public static string TransformUri(string template, IDictionary<string, object> variables);