TemplateRender.cs 744 B

123456789101112131415161718192021222324
  1. using System.Diagnostics;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using AspNetCoreSsrTemplateEngine.DataBoundContext;
  5. namespace AspNetCoreSsrTemplateEngine.Renders
  6. {
  7. [DebuggerDisplay("TEMPLATE: {" + nameof(Key) + ",nq}")]
  8. internal class TemplateRender : IRender
  9. {
  10. public string Key { get; }
  11. public TemplateRender(string key)
  12. {
  13. Key = key;
  14. }
  15. public async Task RenderAsync(IReadonlyDataBindContext dataBindContext, Stream stream)
  16. {
  17. if (false == dataBindContext.TryGetTemplate(Key, out var template)) throw new SteException($"Template `{Key}' not found in context ");
  18. await template.RenderAsync(dataBindContext, stream);
  19. }
  20. }
  21. }