C# CSharp.CSharpFormattingPolicy类代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.CSharpFormattingPolicy的典型用法代码示例。如果您正苦于以下问题:C# CSharpFormattingPolicy类的具体用法?C# CSharpFormattingPolicy怎么用?C# CSharpFormattingPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


C# CSharp.CSharpFormattingPolicy类代码示例

CSharpFormattingPolicy类属于ICSharpCode.NRefactory.CSharp命名空间,在下文中一共展示了CSharpFormattingPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: FormatText

public string FormatText (CSharpFormattingPolicy policy, TextStylePolicy textPolicy, string mimeType, string input, int startOffset, int endOffset)
		{
			var data = new TextEditorData ();
			data.Document.SuppressHighlightUpdate = true;
			data.Document.MimeType = mimeType;
			data.Document.FileName = "toformat.cs";
			if (textPolicy != null) {
				data.Options.TabsToSpaces = textPolicy.TabsToSpaces;
				data.Options.TabSize = textPolicy.TabWidth;
				data.Options.IndentationSize = textPolicy.IndentWidth;
				data.Options.IndentStyle = textPolicy.RemoveTrailingWhitespace ? IndentStyle.Virtual : IndentStyle.Smart;
			}
			data.Text = input;

			// System.Console.WriteLine ("-----");
			// System.Console.WriteLine (data.Text.Replace (" ", ".").Replace ("\t", "->"));
			// System.Console.WriteLine ("-----");

			var parser = new CSharpParser ();
			var compilationUnit = parser.Parse (data);
			bool hadErrors = parser.HasErrors;
			
			if (hadErrors) {
				//				foreach (var e in parser.ErrorReportPrinter.Errors)
				//					Console.WriteLine (e.Message);
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			var originalVersion = data.Document.Version;

			var textEditorOptions = data.CreateNRefactoryTextEditorOptions ();
			var formattingVisitor = new ICSharpCode.NRefactory.CSharp.CSharpFormatter (
				policy.CreateOptions (),
				textEditorOptions
			) {
				FormattingMode = FormattingMode.Intrusive
			};

			var changes = formattingVisitor.AnalyzeFormatting (data.Document, compilationUnit);
			try {
				changes.ApplyChanges (startOffset, endOffset - startOffset);
			} catch (Exception e) {
				LoggingService.LogError ("Error in code formatter", e);
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			// check if the formatter has produced errors
			parser = new CSharpParser ();
			parser.Parse (data);
			if (parser.HasErrors) {
				LoggingService.LogError ("C# formatter produced source code errors. See console for output.");
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			var currentVersion = data.Document.Version;

			string result = data.GetTextBetween (startOffset, originalVersion.MoveOffsetTo (currentVersion, endOffset, ICSharpCode.NRefactory.Editor.AnchorMovementType.Default));
			data.Dispose ();
			return result;
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:60,代码来源:CSharpFormatter.cs

示例2: TestNamespaceBraceStyle

public void TestNamespaceBraceStyle ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
			policy.ClassBraceStyle = BraceStyle.DoNotChange;
			
			var adapter = Test (policy, @"namespace A
{
namespace B {
	class Test {}
}
}",
@"namespace A {
	namespace B {
		class Test {}
	}
}");
			
			policy.NamespaceBraceStyle = BraceStyle.NextLineShifted;
			Continue (policy, adapter,
@"namespace A
	{
	namespace B
		{
		class Test {}
		}
	}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:28,代码来源:TestBraceStlye.cs

示例3: TestBlankLinesBeforeUsings

public void TestBlankLinesBeforeUsings ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.BlankLinesAfterUsings = 0;
			policy.BlankLinesBeforeUsings = 2;
			
			var adapter = Test (policy, @"using System;
using System.Text;
namespace Test
{
}",
@"

using System;
using System.Text;
namespace Test
{
}");
			
			policy.BlankLinesBeforeUsings = 0;
			Continue (policy, adapter, 
@"using System;
using System.Text;
namespace Test
{
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:27,代码来源:TestBlankLineFormatting.cs

示例4: TestClassIndentationInNamespacesCase2

public void TestClassIndentationInNamespacesCase2 ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.NamespaceBraceStyle = BraceStyle.NextLine;
			policy.ClassBraceStyle = BraceStyle.NextLine;
			policy.ConstructorBraceStyle = BraceStyle.NextLine;
			
			Test (policy,
@"using System;

namespace MonoDevelop.CSharp.Formatting {
	public class FormattingProfileService {
		public FormattingProfileService () {
		}
	}
}",
@"using System;

namespace MonoDevelop.CSharp.Formatting
{
	public class FormattingProfileService
	{
		public FormattingProfileService ()
		{
		}
	}
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:28,代码来源:TestTypeLevelIndentation.cs

示例5: TestIndentBlocks

public void TestIndentBlocks ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.IndentBlocks = true;
			
			var adapter = Test (policy,
@"class Test {
	Test TestMethod ()
	{
{
{}
}
	}
}",
@"class Test
{
	Test TestMethod ()
	{
		{
			{}
		}
	}
}");
			policy.IndentBlocks = false;
			Continue (policy, adapter, @"class Test
{
	Test TestMethod ()
	{
		{
		{}
		}
	}
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:34,代码来源:TestStatementIndentation.cs

示例6: TestClassIndentation

public void TestClassIndentation ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.ClassBraceStyle = BraceStyle.DoNotChange;
			
			Test (policy,
@"			class Test {}",
@"class Test {}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:9,代码来源:TestTypeLevelIndentation.cs

示例7: TestClassBraceStlye

public void TestClassBraceStlye ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.ClassBraceStyle = BraceStyle.EndOfLine;
			
			Test (policy,
@"class Test {}",
@"class Test {
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:10,代码来源:TestBraceStlye.cs

示例8: TestStructBraceStyle

public void TestStructBraceStyle ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.StructBraceStyle = BraceStyle.NextLine;
			
			Test (policy,
@"struct Test {}",
@"struct Test
{
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:11,代码来源:TestBraceStlye.cs

示例9: TestClassIndentationInNamespaces

public void TestClassIndentationInNamespaces ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
			policy.ClassBraceStyle = BraceStyle.DoNotChange;
			
			Test (policy,
@"namespace A { class Test {} }",
@"namespace A {
	class Test {}
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:12,代码来源:TestTypeLevelIndentation.cs

示例10: TestFixedFieldSpacesBeforeComma

public void TestFixedFieldSpacesBeforeComma ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.ClassBraceStyle = BraceStyle.EndOfLine;
			policy.SpaceAfterFieldDeclarationComma = true;
			policy.SpaceBeforeFieldDeclarationComma = true;
			
			Test (policy, @"class Test {
	fixed int a[10]           ,                   b[10],          c[10];
}",
	@"class Test {
	fixed int a[10] , b[10] , c[10];
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:14,代码来源:TestSpacingVisitor.cs

示例11: GenerateCode

public void GenerateCode(ITextOutput output, Predicate<IAstTransform> transformAbortCondition)
		{
			TransformationPipeline.RunTransformationsUntil(astCompileUnit, transformAbortCondition, context);
			astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null);
			
			var outputFormatter = new TextOutputFormatter(output);
			var formattingPolicy = new CSharpFormattingPolicy();
			// disable whitespace in front of parentheses:
			formattingPolicy.BeforeMethodCallParentheses = false;
			formattingPolicy.BeforeMethodDeclarationParentheses = false;
			formattingPolicy.BeforeConstructorDeclarationParentheses = false;
			formattingPolicy.BeforeDelegateDeclarationParentheses = false;
			astCompileUnit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null);
		}
开发者ID:eldersantos,项目名称:ILSpy,代码行数:14,代码来源:AstBuilder.cs

示例12: TestFieldSpacesBeforeComma1

public void TestFieldSpacesBeforeComma1 ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.ClassBraceStyle = BraceStyle.EndOfLine;
			policy.SpaceBeforeFieldDeclarationComma = false;
			policy.SpaceAfterFieldDeclarationComma = false;
			
			Test (policy, @"class Test {
	int a           ,                   b,          c;
}",
@"class Test {
	int a,b,c;
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:14,代码来源:TestSpacingVisitor.cs

示例13: TestBug325187

public void TestBug325187 ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.PlaceElseOnNewLine = true;
			
			TestStatementFormatting (policy,
@"foreach (int i in myints)
if (i == 6)
Console.WriteLine (""Yeah"");
else
Console.WriteLine (""Bad indent"");",
@"foreach (int i in myints)
	if (i == 6)
		Console.WriteLine (""Yeah"");
	else
		Console.WriteLine (""Bad indent"");");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:17,代码来源:TestFormattingBugs.cs

示例14: TestBug415469

public void TestBug415469 ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			
			TestStatementFormatting (policy,
@"switch (condition) {
case CONDITION1:
return foo != null ? foo.Bar : null;
case CONDITION2:
string goo = foo != null ? foo.Bar : null;
return ""Should be indented like this"";
}", @"switch (condition) {
case CONDITION1:
	return foo != null ? foo.Bar : null;
case CONDITION2:
	string goo = foo != null ? foo.Bar : null;
	return ""Should be indented like this"";
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:19,代码来源:TestFormattingBugs.cs

示例15: TestInvocationIndentation

public void TestInvocationIndentation ()
		{
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.ClassBraceStyle = BraceStyle.EndOfLine;
			
			Test (policy,
@"class Test {
	Test TestMethod ()
	{
this.TestMethod ();
	}
}",
@"class Test {
	Test TestMethod ()
	{
		this.TestMethod ();
	}
}");
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:19,代码来源:TestStatementIndentation.cs

本文标签属性:

示例:示例是什么意思

代码:代码编程

CSharpFormattingPolicy:CSharpFormattingPolicy

CSharp:csharp是什么

上一篇:Java PropertyName类代码示例(javapropertyname类代码示例汇总)
下一篇:窨井的简介(窨井是什么?)

为您推荐