Last active
July 15, 2016 04:27
-
-
Save itn3000/a0fc6ff6833340a8d5c16e9fa3ade62c to your computer and use it in GitHub Desktop.
cs file code formatting in program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp4 | |
{ | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.Text; | |
using Microsoft.CodeAnalysis.Formatting; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// original code | |
var code = @"using System; | |
namespace | |
a | |
{ | |
class | |
b | |
{ | |
} | |
}"; | |
using (var adhoc = new AdhocWorkspace()) | |
{ | |
var proj = adhoc.AddProject("hoge.csproj", LanguageNames.CSharp); | |
var doc = proj.AddDocument("hoge.cs", SourceText.From(code)); | |
doc = Formatter.FormatAsync(doc).Result; | |
Console.WriteLine($"{doc.GetTextAsync().Result}"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "1.0.0-*", | |
"buildOptions": { | |
"emitEntryPoint": true | |
}, | |
"dependencies": { | |
"Microsoft.NETCore.App": { | |
"type": "platform", | |
"version": "1.0.0" | |
}, | |
"Microsoft.CodeAnalysis.CSharp": "1.3.2", | |
"Microsoft.CodeAnalysis.CSharp.Workspaces": "1.3.2" | |
}, | |
"frameworks": { | |
"netcoreapp1.0": { | |
"imports": [ | |
"portable-net45" | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment