private void OnDoReformat(object sender, EventArgs e) { CSharpFormatter formatter = new CSharpFormatter(FormattingOptionsFactory.CreateAllman()); string newText = formatter.Format(this.managerView.Editor.Text); this.managerView.Editor.Text = newText; this.explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(this.manager, "Code", newText)); }
static string FormattedString(string filePath) { var readed = File.ReadAllText(filePath); var option = FormattingOptionsFactory.CreateMono(); var textEditorOption = new TextEditorOptions(); var formatter = new CSharpFormatter(option, textEditorOption); return(formatter.Format(readed)); }
public CodeFormatResponse Format(CodeFormatRequest request) { var options = _config.TextEditorOptions; var policy = _config.CSharpFormattingOptions; var formatter = new CSharpFormatter(policy, options); formatter.FormattingMode = FormattingMode.Intrusive; var output = formatter.Format(request.Buffer); return(new CodeFormatResponse(output)); }
/// <summary> /// Perform a reformat of the text /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void OnDoReformat(object sender, EventArgs e) { try { CSharpFormatter formatter = new CSharpFormatter(FormattingOptionsFactory.CreateAllman()); string newText = formatter.Format(managerView.Editor.Text); managerView.Editor.Text = newText; explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(manager, "Code", newText)); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } }
private void FormatSourceCode(string fileName, CSharpFormattingOptions formatStyle) { CSharpParser parser = new CSharpParser(); // Open the C# source file to read using (TextReader sr = new StreamReader(fileName)) { // TO DO: TextEditorOptions CSharpFormatter formater = new CSharpFormatter(formatStyle); formater.Format(sr.ReadToEnd()); // Write the new C# source file if modified } }
/// <summary> /// Formats the file /// </summary> static string FormatFile(ICSharpCode.NRefactory.CSharp.SyntaxTree file) { var formatting = FormattingOptionsFactory.CreateMono(); formatting.AutoPropertyFormatting = PropertyFormatting.ForceOneLine; formatting.SimplePropertyFormatting = PropertyFormatting.ForceOneLine; var formatter = new CSharpFormatter(formatting) { FormattingMode = FormattingMode.Intrusive }; return(formatter.Format(file.ToString())); }
protected static void Continue(CSharpFormattingOptions policy, IDocument document, string expectedOutput, FormattingMode formattingMode = FormattingMode.OnTheFly) { expectedOutput = NormalizeNewlines(expectedOutput); var options = new TextEditorOptions(); options.EolMarker = "\n"; var formatter = new CSharpFormatter(policy, options); formatter.FormattingMode = formattingMode; string newText = formatter.Format(document); if (expectedOutput != newText) { Console.WriteLine(newText); } Assert.AreEqual(expectedOutput, newText); }
/// <summary> /// 実際にフォーマットを行う /// </summary> /// <param name="path">フォーマットするファイルへのパス</param> private static void Format(string path) { // フォーマットを行うソースコードを全て読み込む string targetSourceCode; using (var reader = new StreamReader(path)) { targetSourceCode = reader.ReadToEnd(); } // ソースコードをフォーマットする CSharpFormatter formatter = new CSharpFormatter(FormattingOptions.options); var formatSourceCode = formatter.Format(targetSourceCode); // 同じファイル名で出力する using (var writer = new StreamWriter(path)) { writer.Write(formatSourceCode); } }
protected override string Transform(string code, string fileName, Action <ValidationResult> notify) { var formatter = new CSharpFormatter(_options); return(formatter.Format(code)); }