Exemplo n.º 1
0
        private string ReplaceTags(string message)
        {
            var regex = new Regex(@"\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}");

            return(regex.Replace(message, match =>
            {
                string key = match.Groups["key"].Value;
                return contextData.AsStringOrDefault(key) ?? match.Groups["default"].Value;
            }));
        }
        private string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            string pattern = @"(?<!\{)\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}(?!\})";

            return(Regex.Replace(message, pattern, match =>
            {
                string key = match.Groups["key"].Value;
                return contextData.AsStringOrDefault(key)?.Replace("{", "{{").Replace("}", "}}") ?? match.Groups["default"].Value;
            }));
        }
Exemplo n.º 3
0
        private string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            var regex = new Regex(@"\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}");

            return(regex.Replace(message, match =>
            {
                string key = match.Groups["key"].Value;
                return
                contextData.AsStringOrDefault(key)?.Replace("{", "{{").Replace("}", "}}") ??
                match.Groups["default"].Value;
            }));
        }
Exemplo n.º 4
0
        private static string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            const string pattern = @"(?<!\{)\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}(?!\})";

            return(Regex.Replace(message, pattern, match =>
            {
                string key = match.Groups["key"].Value;
                string contextualTags = contextData.AsStringOrDefault(key);
                string contextualTagsSubstituted = contextualTags?.EscapePlaceholders();

                return contextualTagsSubstituted ?? match.Groups["default"].Value;
            }));
        }