-
Notifications
You must be signed in to change notification settings - Fork 30
Saving code
Mille Boström edited this page Jun 23, 2017
·
1 revision
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");
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