Skip to content

Instantly share code, notes, and snippets.

@itn3000
Last active July 15, 2016 04:27
Show Gist options
  • Save itn3000/a0fc6ff6833340a8d5c16e9fa3ade62c to your computer and use it in GitHub Desktop.
Save itn3000/a0fc6ff6833340a8d5c16e9fa3ade62c to your computer and use it in GitHub Desktop.
cs file code formatting in program
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}");
}
}
}
}
{
"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