1、创建项目,添加新项,名称处填写Messages.tt,如下图:

使用T4模板创建一个例子

添加后,Messages.tt文件内容如下:

1 <#@ template debug="false" hostspecific="false" language="C#" #>
2 <#@ output extension=".txt" #>

2、创建一个实体对象MessageEntry,用以传递模版信息,具体代码如下:

 1     public class MessageEntry
 2     {
 3         public string Id { get; private set; }
 4         public string Value { get; private set; }
 5         public string Category { get; private set; }
 6         public MessageEntry(string id, string value, string category)
 7         {
 8             this.Id = id;
 9             this.Value = value;
10             this.Category = category;
11         }
12 
13         public string Format(params object[] args)
14         {
15             return string.Format(this.Value, args);
16         }
17     }
MessageEntry.cs

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-08-01
  • 2021-07-18
  • 2022-02-27
猜你喜欢
  • 2021-10-22
  • 2021-07-13
  • 2022-01-15
  • 2021-10-25
  • 2021-10-06
  • 2021-07-29
相关资源
相似解决方案