コード例 #1
0
        private string RenderBodyTemplate(MessageContext ctx)
        {
            var key       = BuildTemplateKey(ctx);
            var source    = ctx.MessageTemplate.GetLocalized((x) => x.Body, ctx.Language);
            var fromCache = true;
            var template  = _templateManager.GetOrAdd(key, GetBodyTemplate);

            if (fromCache && template.Source != source)
            {
                // The template was resolved from template cache, but it has expired
                // because the source text has changed.
                template = _templateEngine.Compile(source);
                _templateManager.Put(key, template);
            }

            return(template.Render(ctx.Model, ctx.FormatProvider));

            string GetBodyTemplate()
            {
                fromCache = false;
                return(source);
            }
        }