I want to be able to rename classes using dotnet new project templates like these examples
I want to have files/classes that have the same name as the project with a suffix that automatically rename to match the project
eg [projectname]DbContext, ProjectNameDto so if my template is called MyWebTemplate and it has a class MyWebTempaleDbContext and the user picks a name Of MyWebApp the file and class would be renamed to MyWebAppDbContext.
I am able to do this with parameters, but want to do this for multiple classes and dont want to have to add a parameter for this
here is how it can be done with parameters :
"DBContextName": {
"type": "parameter",
"defaultValue": "WebApplicationDbContext",
"replaces": "WebApplicationDbContext",
"FileRename": "WebApplicationDbContext",
"datatype": "text",
"description": "Db Context Name"
},
Is there a way to do this using RegEx or regex match?
The example they give is :
"symbols": {
"regexExample": {
"type": "generated",
"generator": "regex",
"dataType": "string",
"replaces": "A different message", //The value to replace in the output
"parameters": {
"source": "message", //The name of the symbol whose value should be operated on
"steps": [
{
"regex": "^test", //The regular expression whose matches will be replaced with '[Replaced]`
"replacement": "[Replaced]" //The value to replace matches of the expression '^test' with
},
{
"regex": "test$",
"replacement": "[/Replaced]"
}
]
}
}
}
I also found a file rename example but cant seem to work out how to make the 2 do what i want:
{
...
"symbols": {
"app1Rename": {
"type": "derived",
"valueSource": "name",
"valueTransform": "ValueAfterLastDot",
"fileRename": "Application1",
"description": "A value derived from the 'name' param, used to rename Application1.cs"
}
}
...
"forms": {
"ValueAfterLastDot": {
"identifier": "replace",
"pattern": "^.*\\.(?=[^\\.]+$)", // regex to match everything up to and including the final "."
"replacement": "" // replace it with empty string
}
}
...
}
Thanks