protected void Render(TemplateContext context, TextWriter writer) { if (context == null) { writer.Write(this.TemplateContent); return; } if (!String.IsNullOrEmpty(this.TemplateContent)) { TemplateLexer lexer = new TemplateLexer(this.TemplateContent); TemplateParser parser = new TemplateParser(lexer.Parse()); while (parser.MoveNext()) { try { parser.Current.Parse(context, writer); } catch (Exception.TemplateException e) { if (context.ThrowExceptions) { throw e; } else { context.AddError(e); writer.Write(parser.Current.ToString()); } } catch (System.Exception e) { System.Exception baseException = e.GetBaseException(); Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException); if (context.ThrowExceptions) { throw ex; } else { context.AddError(ex); writer.Write(parser.Current.ToString()); } } } } }
/// <summary> /// 呈现标签 /// </summary> /// <param name="context">上下文</param> /// <param name="writer">writer</param> protected void Render(TemplateContext context, TextWriter writer) { //缓存功能,待添加 if (context == null) { writer.Write(this.TemplateContent); return; } Tag[] collection; if (!String.IsNullOrEmpty(this.TemplateContent)) { TemplateLexer lexer = new TemplateLexer(this.TemplateContent, context.Config.TagFlag, context.Config.TagPrefix, context.Config.TagSuffix); TemplateParser parser = new TemplateParser(lexer.Parse(), context.Config.Resolver); collection = parser.ToArray(); } else { collection = new Tag[0]; } if (collection.Length > 0) { for (Int32 i = 0; i < collection.Length; i++) { try { collection[i].Parse(context, writer); } catch (Exception.TemplateException e) { if (context.ThrowExceptions) { throw e; } else { context.AddError(e); writer.Write(collection[i].ToString()); } } catch (System.Exception e) { System.Exception baseException = e.GetBaseException(); Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException); if (context.ThrowExceptions) { throw ex; } else { context.AddError(ex); writer.Write(collection[i].ToString()); } } } } }