private static string ReplaceTemplates(string patternFormat, Dictionary<string, TemplateReplacerBase> replacers, string queryText, object parameters)
{
foreach (var templateName in replacers.Keys)
{
var templatePattern = string.Format(patternFormat ?? TEMPLATE_PATTERN_FORMAT, templateName);
var index = 0;
var regex = new Regex(templatePattern, RegexOptions.IgnoreCase);
while (true)
{
var match = regex.Match(queryText, index);
if (!match.Success)
break;
var propName = match.Groups["PropertyName"];
var templateValue = replacers[templateName].EvaluateTemplate(templateName, propName == null ? null : propName.Value, parameters) ?? string.Empty;
queryText = queryText
.Remove(match.Index, match.Length)
.Insert(match.Index, templateValue);
index = match.Index + templateValue.Length;
if (index >= queryText.Length)
break;
}
}
return queryText;
}