Blame view

netcore/src/Infrastructure/NCC/ViewEngine/Internal/ViewEnginePartSetters.cs 2.31 KB
de2bd2f9   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  using System;
  
  namespace NCC.ViewEngine
  {
      /// <summary>
      /// 字符串模板执行部件
      /// </summary>
      public sealed partial class ViewEnginePart
      {
          /// <summary>
          /// 设置模板
          /// </summary>
          /// <param name="template"></param>
          /// <returns></returns>
          public ViewEnginePart SetTemplate(string template)
          {
              if (!string.IsNullOrWhiteSpace(template)) Template = template;
              return this;
          }
  
          /// <summary>
          /// 设置模板数据
          /// </summary>
          /// <typeparam name="T"></typeparam>
          /// <param name="model"></param>
          /// <returns></returns>
          public ViewEnginePart SetTemplateModel<T>(T model)
              where T : class, new()
          {
              TemplateModel = (typeof(T), model);
              return this;
          }
  
          /// <summary>
          /// 设置模板数据
          /// </summary>
          /// <param name="model"></param>
          /// <returns></returns>
          public ViewEnginePart SetTemplateModel(object model)
          {
              return SetTemplateModel<object>(model);
          }
  
          /// <summary>
          /// 设置模板构建选项
          /// </summary>
          /// <param name="optionsBuilder"></param>
          /// <returns></returns>
          public ViewEnginePart SetTemplateOptionsBuilder(Action<IViewEngineOptionsBuilder> optionsBuilder = default)
          {
              if (optionsBuilder != null) TemplateOptionsBuilder = optionsBuilder;
              return this;
          }
  
          /// <summary>
          /// 设置模板缓存文件名(不含拓展名)
          /// </summary>
          /// <param name="cachedFileName"></param>
          /// <returns></returns>
          public ViewEnginePart SetTemplateCachedFileName(string cachedFileName)
          {
              if (!string.IsNullOrWhiteSpace(cachedFileName)) TemplateCachedFileName = cachedFileName;
              return this;
          }
  
          /// <summary>
          /// 视图模板服务作用域
          /// </summary>
          /// <param name="serviceProvider"></param>
          /// <returns></returns>
          public ViewEnginePart SetViewEngineScoped(IServiceProvider serviceProvider)
          {
              if (serviceProvider != null) ViewEngineScoped = serviceProvider;
              return this;
          }
      }
  }