Saving code - Testura/Testura.Code GitHub Wiki
Example
Example of saving code:
var saver = new CodeSaver();
// As a string
var generatedCode = saver.SaveCodeAsString(@class);
// Or to file
saver.SaveCodeToFile(@class, @"/path/HelloWorld.cs");
Customize formatting with options
It's possible to customize the formatting before saving by using the option list. A short example where we change OneTrueBrace style to K&R style:
var codeSaver = new CodeSaver(new List<OptionKeyValue> { new OptionKeyValue(CSharpFormattingOptions.NewLinesForBracesInMethods, false) });
var code = codeSaver.SaveCodeAsString(
new ClassBuilder("TestClass", "test")
.WithMethods(
new MethodBuilder("MyMethod")
.Build())
.Build());
For a full list of possible formatting checkout Roslyn: https://github.com/dotnet/roslyn/blob/master/src/Workspaces/CSharp/Portable/Formatting/CSharpFormattingOptions.cs