✅ Is there a way to programmatically formatt a file
Im writing a transpiler to C# (in C#) and I would like to formatt the output files after I write them to C# does anybody know how to do this? Roslyn does not work:
SOLUTION FOUND by SleepWellPupper
14 Replies
The above results in no change to the src code
Code formatting is not a concern of Roslyn or any other part of the toolchain
It's an IDE concern
So you'll probably have to either find some code formatting library
Or... just write formatted code in the first place
Also, you got an
async void
there
BadIf you use any decent editor you should be able to format the entire document with a hotkey
After all how code is written and how its designed is mostly a choice of the user
Its the conventions people willingly stick to
Not my post, but can you explain why it's bad?
:plink:
It's fire and forget
An
async Task
method returns something, a task
It can be awaited, canceled, scheduled, deferred in execution, anythingAaah
I see
async void
means nothing gets returned
Can't await nothing, can't cancel nothingI see
Thank uuu
Anytime :Ok:
Yea the transpiler is built for people who don't know how to code (Its a data scripting language) In theory they should be able to look at the code without it looking like hieroglyphs or never look at the code, the goal of the language is to kinda point people in the right direction on how to actually code, knowing the command CTRL + K + CTRL + D may seem obvious to people who code but to someone who has never coded they would probably just think that coding is supposed to look like minified code on one line.
Stack Overflow
Generating well-formatted syntax with Roslyn
I am using Roslyn to modify the syntax of C# files. Using CSharpSyntaxRewriter, it is very easy to find and replace nodes in the syntax tree. However, the generated code is very ugly and won't even...
There are limits to what can be done using this approach, it'll do a rudimentary job though. You have to do the legwork manually via your transpiler output.
Thank you that worked!🙂
$close
If you have no further questions, please use /close to mark the forum thread as answered