private string ApplyReplacements(string text) { MatchCollection matches = regexReplacement.Matches(text); var blocksList = new List<TextBlock>(matches.Count); foreach (Match match in matches) { string tag = ignoreCase ? match.Groups["tag"].Value.ToUpper() : match.Groups["tag"].Value; string result; if (!replacements.TryGetValue(tag, out result)) { throw new InvalidOperationException("Trying to replace an unknown tag named '" + tag + "', please check your tag dictionary!"); } var block = new TextBlock { Start = match.Index, End = match.Index + match.Length - 1, Text = result, }; blocksList.Add(block); } return UpdateBlocks(text, blocksList); }
private string ApplyConditions(string text) { MatchCollection matches = regexIf.Matches(text); var blocksList = new List<TextBlock>(matches.Count); foreach (Match match in matches) { string condition = match.Groups["condition"].Value; var block = new TextBlock { Start = match.Index, End = match.Index + match.Length - 1, }; if (evaluator.Evaluate(condition)) { block.Text = match.Groups["text"].Value; } blocksList.Add(block); } return UpdateBlocks(text, blocksList); }