Inline code formatter or something ¯_(ツ)_/¯
I've been developing an extension for Visual Studio that can insert code snippets with given declaration, so I needed to get rid of this: so i decided to quickly make this thing.
CodeTextBuilder b = new CodeTextBuilder()
{
"//Comment",
new CodeTextBlock("if(true)")
{
"return 0;"
}
};
string result = b.Build(0);
Output:
String view:
"//Comment\nif(true)\n{\n\treturn 0;\n}"
To create a line you can use strings or CodeTextLine with custom indent value:
CodeTextBuilder b = new CodeTextBuilder()
{
new CodeTextLine("This is a line with indent of 2", 2),
"//Comment",
new CodeTextBlock("if(true)")
{
"return 0;"
}
};
string a = b.Build(0);
String view:
"\t\tThis is a line with indent of 2\n//Comment\nif(true)\n{\n\treturn 0;\n}"
Output:
CodeTextBuilder b = new CodeTextBuilder()
{
new CodeTextLine("All the code is two tabs right", 0),
"//Comment",
new CodeTextBlock("if(true)")
{
"return 0;"
}
};
string a = b.Build(2);
Output: