コード例 #1
0
ファイル: TemplateExtensions.cs プロジェクト: yuanfei05/vita
 public static ITextTemplate NewTextTemplate(this IEntitySession session, string name, string template, TemplateFormat format, 
     string culture = "EN-US", string engine = "Simple", Guid? ownerId = null)
 {
     var templ = session.NewEntity<ITextTemplate>();
       templ.Name = name;
       templ.Template = template;
       templ.Format = format;
       templ.Culture = culture;
       templ.Engine = engine;
       templ.OwnerId = ownerId;
       return templ;
 }
コード例 #2
0
 public string Transform(string template, TemplateFormat format, IDictionary<string, object> data)
 {
     var result = template;
       var entries = data.ToList();
       foreach(var kv in entries) {
     //Quick check without braces/tags
     if(!result.Contains(kv.Key))
       continue;
     var tag = OpenTag + kv.Key + EndTag;
     var strValue = kv.Value + string.Empty; //safe ToString()
     if(!string.IsNullOrWhiteSpace(strValue) && format == TemplateFormat.Html)
       strValue = StringHelper.EscapeForHtml(strValue);
     result = result.Replace(tag, strValue);
       }
       if(result.Contains(EscapedOpenTag))
     result = result.Replace(EscapedOpenTag, OpenTag);
       return result;
 }