Example #1
0
        public string Replace(string text, IDictionary<string, object> data, ReplaceOptions options) {
            var tokenset = Parse(text);
            var tokens = tokenset.Item2;
            var replacements = Evaluate(options.Predicate == null ? tokens : tokens.Where(options.Predicate), data);

            return replacements.Aggregate(tokenset.Item1,
                (current, replacement) => current.Replace("{" + replacement.Key + "}", (options.Encoding ?? ReplaceOptions.NoEncode)(replacement.Key, replacement.Value)));
        }
        public string Replace(string text, IDictionary<string, object> data, ReplaceOptions options) {
            if (String.IsNullOrEmpty(text)) {
                return String.Empty;
            }

            // do we have to replace tokens with hashes ?
            bool hashMode = text.Contains("#{");

            var tokenset = Parse(text, hashMode);
            var tokens = tokenset.Item2;
            var replacements = Evaluate(options.Predicate == null ? tokens : tokens.Where(options.Predicate), data);

            return replacements.Aggregate(tokenset.Item1,
                (current, replacement) => current.Replace((hashMode ? "#{" : "{") + replacement.Key + "}", (options.Encoding ?? ReplaceOptions.NoEncode)(replacement.Key, replacement.Value)));
        }
 public string Replace(string text, object data, ReplaceOptions options) {
     return Replace(text, new RouteValueDictionary(data), options);
 }