做类似的事情
我正在使用Swagger-Codegen生成数据模型。模板
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
/// </summary>{{#description}}
/// <value>{{description}}</value>{{/description}}
[JsonProperty("{{baseName}}")]
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
生成
/// <summary>
/// Description of property.
/// </summary>
/// <value>Description of property.</value>
[JsonProperty("property_name")]
public String property_name { get; set; }
如何将property name
的情况从Sneke_case更改为Pascalcase?我想我必须对{{name}}
进行某种转换,但我对车把模板不太熟悉。
/// <summary>
/// Description of property.
/// </summary>
/// <value>Description of property.</value>
[JsonProperty("property_name")]
public String PropertyName { get; set; }
我不知道Swagger Codegen是否内置了任何内置的东西,但是使用handlebars.net,您可以注册一个助手将字符串转换为pascalcase:
Handlebars.RegisterHelper("PascalCase", (writer, context, parameters) => {
// paramaters[0] should be name, convert it to PascalCase here
});
我的c#足够尘土飞扬,我不记得是否有一种pascalcalcalcasscas绳子的方式,但是如果没有的话,这不应该太难了。
然后从模板中调用它:
public {{{datatype}}} {{PascalCase name}} ...
编辑:看起来像Swagger Codegen在引擎盖下使用Jmustache,并且可以快速浏览,但我认为您可以使用Lambdas