英文:
How to replace a parameter value with lowercase in a C# project template using Visual Studio
问题
我试图创建一个C#项目模板,并在模板配置中有一个名为"MyClass"的输入参数。我希望在模板中的"MyClass"被替换后,能够将其实例更改为小写,这是我想生成所有类的示例类模板:
//This is myClass <- 将此更改为小写 (myClass)
public class MyClass <- 保持不变 (MyClass)
{
}
如果我从模板生成一个名为"School"的类,我希望输出如下:
//This is school <- 此替换已更改为全小写
public class School <- 此替换未更改
{
}
以下是我的模板的当前配置:
{
"name": "Test",
"shortName": "test",
"preferNameDirectory": true,
"tags": {
"language": "C#",
"type": "item"
},
"symbols": {
"MyClass": {
"type": "parameter",
"datatype": "text",
"description": "Renames files containing 'MyClass'",
"fileRename": "MyClass",
"replaces": "MyClass",
"isRequired": true,
"defaultValue": "MyClass"
}
}
}
注意:模板文件的构建操作已设置为内容,无法进行编译,因此无法执行ToLower()等操作。
英文:
I am trying to create a project template for C# and I have an input parameter named "MyClass" as shown in the template configuration below. I want to be able to change the instances of "MyClass" to lowercase if I want after it has been replaced in the template.
This is a sample class template that I want to generate all classes from:
//This is myClass <- Change this to lowercase (myClass)
public class MyClass <- Leave this as it is (MyClass)
{
}
If I generate a class named "School" from the template, I want the output to be like this:
//This is school <- This replacement was changed to all lowercase
public class School <- This replacement was left unchanged
{
}
Here's the current configuration of my template:
{
"name": "Test",
"shortName": "test",
"preferNameDirectory": true,
"tags": {
"language": "C#",
"type": "item"
},
"symbols": {
"MyClass": {
"type": "parameter",
"datatype": "text",
"description": "Renames files containing 'MyClass'",
"fileRename": "MyClass",
"replaces": "MyClass",
"isRequired": true,
"defaultValue": "MyClass"
}
}
}
NOTE: The build action of the template file has been set to content and cannot be compiled so I cannot do things like ToLower().
答案1
得分: 1
I don't understand your Note:
, do you mean you can't modify this template? So how can you get what you need.
You should modify to add valueTransform
attribute, this should solve your problem.
"valueTransform": "firtstLowerCase"
英文:
I don't understand your Note:
, do you mean you can't modify this template? So how can you get what you need.
You should modify to add valueTransform
attribute, this should solve your problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论