Here is my dirty-but-help-a-bit method, mainly regex stuff.
! Answer in progress, just saving from time to time to avoid the dreaded back button
1: cleaning: format
Make sure the declarations are all in one line per function, IMO that will help sorting that out.
input:
public async Task<IList<AnalysisResult>> GetAnalysis(short year, bool unPlanned = false,
Guid? departmentId = null, Guid? personnelId = null, CollarColor? collarColor = null,Guid? factoryId = null)
{
...
}
public async Task<IList<AnalysisResult>> GetOtherStuff(string foo = "bar", bool foobar = false, Guid? factoryId = null)
{
...
}
REGEX: ,\r\n
REPLACE BY: ,
output :
public async Task<IList<AnalysisResult>> GetAnalysis(short year, bool unPlanned = false, Guid? departmentId = null, Guid? personnelId = null, CollarColor? collarColor = null,Guid? factoryId = null)
{
...
}
public async Task<IList<AnalysisResult>> GetOtherStuff(string foo = "bar", bool foobar = false, Guid? factoryId = null)
{
...
}
2: more cleaning: filter and create individual files
For this, need to work in a dedicated folder.
Take your input file from the result above. In the script below, it's "input.cs"
Let's take only the lines starting by "public" or "public async Task" if they're all async.
Create a script like filter.ps1
$regex = "^\s*public async Task[^(]*\s+([^(]+)" #capture the name of the function, i.e. the part before the opening parenthesis and space after Task<... type
get-content input.cs | % { if($_ -match $regex) {Set-Content -Path "$($matches[1])Payload.cs" -Value $_ } }
and execute it in the folder where only the script and the file input.cs are present.
Disclaimer: in the above code, I assume you don't have parenthesis, or space in the return type of the function! That could happen if you have some generic method with several type parameters, or Tuples.
output : 2 separate files, GetAnalysisPayload.cs
and GetOtherStuffPayload.cs
each with only the function declaration line.
3: split each line cleverly
Split on (
and ,
, with some clever format, that will give the "DTO class header" first, and the list of parameters.
(regex / powershell code to be given)
That might get messy depending what you have at this step, but if functions are like your example, it could give you a pretty close approximation of what you need at this step already..
Then
With some time (a couple of hours?) I would have polished that with a Powershell script or C# console app, to save you part of the "unavoidable" remaining manual work.
for instance, add the "using" statements needed on top of each file.
I'm quoting "unvoidable", because it is told at night that some Regex wizards out there are able to take care of this job with regexes only.