/// <summary>根据名称和模版创建模版实例,带缓存,避免重复编译</summary> /// <param name="templates">模版集合</param> /// <returns></returns> public static Template Create(IDictionary <String, String> templates) { if (templates == null || templates.Count < 1) { throw new ArgumentNullException("templates"); } // 计算hash var sb = new StringBuilder(); foreach (var item in templates) { sb.Append(Hash(item.Key)); sb.Append(Hash(item.Value)); } var hash = Hash(sb.ToString()); return(cache.GetItem(hash, k => { var entity = new Template(); foreach (var item in templates) { entity.AddTemplateItem(item.Key, item.Value); } //entity.Process(); //entity.Compile(); return entity; })); }
/// <summary>根据名称和模版创建模版实例,带缓存,避免重复编译</summary> /// <param name="templates">模版集合</param> /// <returns></returns> public static Template Create(IDictionary <String, String> templates) { if (templates == null || templates.Count < 1) { throw new ArgumentNullException("templates"); } // 计算hash StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <String, String> item in templates) { sb.Append(Hash(item.Key)); sb.Append(Hash(item.Value)); } String hash = Hash(sb.ToString()); return(cache.GetItem <IDictionary <String, String> >(hash, templates, delegate(String key, IDictionary <String, String> contents) { Template entity = new Template(); foreach (KeyValuePair <String, String> item in contents) { entity.AddTemplateItem(item.Key, item.Value); } //entity.Process(); //entity.Compile(); return entity; })); }
/// <summary>根据名称和模版创建模版实例,带缓存,避免重复编译</summary> /// <param name="templates">模版集合</param> /// <returns></returns> public static Template Create(IDictionary<String, String> templates) { if (templates == null || templates.Count < 1) throw new ArgumentNullException("templates"); // 计算hash StringBuilder sb = new StringBuilder(); foreach (KeyValuePair<String, String> item in templates) { sb.Append(Hash(item.Key)); sb.Append(Hash(item.Value)); } String hash = Hash(sb.ToString()); return cache.GetItem<IDictionary<String, String>>(hash, templates, delegate(String key, IDictionary<String, String> contents) { Template entity = new Template(); foreach (KeyValuePair<String, String> item in contents) { entity.AddTemplateItem(item.Key, item.Value); } //entity.Process(); //entity.Compile(); return entity; }); }