Skip to content

Amyst82/CodeBlockBuilder

Repository files navigation

CodeBlockBuilder

Inline code formatter or something ¯_(ツ)_/¯

Why

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: image_2022-08-30_08-35-02 so i decided to quickly make this thing.

Usage

CodeTextBuilder b = new CodeTextBuilder() 
{ 
    "//Comment",
    new CodeTextBlock("if(true)")
    {
       "return 0;"
    }
};
string result = b.Build(0);

Output:

VsDebugConsole_JBtMp6yVaN

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:

VsDebugConsole_EczeSLmWK2

Build method argument is used for defining an "initial" indent e.g.:

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:

VsDebugConsole_bAiXWoXLWa

Demo

46gNxBA31z

About

Inline code formatter or something.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages