Format() public method

Format the specified document and gives back the formatted text as result.
public Format ( IDocument document ) : string
document IDocument
return string
Beispiel #1
0
 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);
 }
 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);
 }
Beispiel #3
0
		/// <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 ());
		}