本文整理汇总了C#中CSharpFormattingPolicy类的典型用法代码示例。如果您正苦于以下问题:C# CSharpFormattingPolicy类的具体用法?C# CSharpFormattingPolicy怎么用?C# CSharpFormattingPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpFormattingPolicy类属于命名空间,在下文中一共展示了CSharpFormattingPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNamespaceBraceStyle
public void TestNamespaceBraceStyle ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text = @"namespace A
{
namespace B {
class Test {}
}
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
policy.ClassBraceStyle = BraceStyle.DoNotChange;
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
Assert.AreEqual (@"namespace A {
namespace B {
class Test {}
}
}", data.Document.Text);
policy.NamespaceBraceStyle = BraceStyle.NextLineShifted;
compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
Assert.AreEqual (@"namespace A
{
namespace B
{
class Test {}
}
}", data.Document.Text);
}
示例2: TestIndentClassBody
public void TestIndentClassBody ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text =
@"class Test
{
Test a;
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.IndentClassBody = true;
CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
Assert.AreEqual (@"class Test
{
Test a;
}", data.Document.Text);
policy.IndentClassBody = false;
compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
Assert.AreEqual (@"class Test
{
Test a;
}", data.Document.Text);
}
示例3: TestBlankLinesAfterUsings
public void TestBlankLinesAfterUsings ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text = @"using System;
using System.Text;
namespace Test
{
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.BlankLinesAfterUsings = 2;
var compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
Assert.AreEqual (@"using System;
using System.Text;
namespace Test
{
}", data.Document.Text);
policy.BlankLinesAfterUsings = 0;
compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
Assert.AreEqual (@"using System;
using System.Text;
namespace Test
{
}", data.Document.Text);
}
示例4: AddProfile
public static void AddProfile (CSharpFormattingPolicy profile)
{
profiles.Add (profile);
if (!Directory.Exists (ProfilePath))
Directory.CreateDirectory (ProfilePath);
string fileName = Path.Combine (ProfilePath, profile.Name + ".xml");
profile.Save (fileName);
}
示例5: CSharpIndentEngine
// Constructors
public CSharpIndentEngine (CSharpFormattingPolicy policy)
{
if (policy == null)
throw new ArgumentNullException ("policy");
this.policy = policy;
stack = new IndentStack (this);
linebuf = new StringBuilder ();
Reset ();
}
示例6: CSharpFormattingPolicies
public CSharpFormattingPolicies()
{
// Load global settings
GlobalOptions = new CSharpFormattingPolicy(
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer() {
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.GlobalOptionReference}")
});
GlobalOptions.FormattingPolicyUpdated += OnFormattingPolicyUpdated;
GlobalOptions.Load();
}
示例7: CSharpFormattingOptionPanel
public CSharpFormattingOptionPanel(CSharpFormattingPolicy persistenceHelper, bool allowPresets, bool overrideGlobalIndentation)
{
if (persistenceHelper == null)
throw new ArgumentNullException("persistenceHelper");
this.formattingPolicy = persistenceHelper;
this.isDirty = false;
InitializeComponent();
formattingEditor.AllowPresets = allowPresets;
formattingEditor.OverrideGlobalIndentation = overrideGlobalIndentation;
}
示例8: CSharpFormattingPolicyPanelWidget
public CSharpFormattingPolicyPanelWidget ()
{
// ReSharper disable once DoNotCallOverridableMethodsInConstructor
this.Build ();
policy = new CSharpFormattingPolicy ();
buttonEdit.Clicked += HandleButtonEditClicked;
texteditor.Options = DefaultSourceEditorOptions.PlainEditor;
texteditor.IsReadOnly = true;
texteditor.MimeType = CSharpFormatter.MimeType;
scrolledwindow1.AddWithViewport (texteditor);
ShowAll ();
}
示例9: TestClassIndentation
public void TestClassIndentation ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text =
@" class Test {}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.ClassBraceStyle = BraceStyle.DoNotChange;
var compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
Assert.AreEqual (@"class Test {}", data.Document.Text);
}
示例10: 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"");");
}
示例11: CSharpFormattingPolicyPanelWidget
public CSharpFormattingPolicyPanelWidget ()
{
this.Build ();
policy = new CSharpFormattingPolicy ();
buttonEdit.Clicked += HandleButtonEditClicked;
var options = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance;
texteditor.Options.FontName = options.FontName;
texteditor.Options.ColorScheme = options.ColorScheme;
texteditor.Options.ShowFoldMargin = false;
texteditor.Options.ShowIconMargin = false;
texteditor.Options.ShowLineNumberMargin = false;
texteditor.Document.ReadOnly = true;
texteditor.Document.MimeType = CSharpFormatter.MimeType;
scrolledwindow1.Child = texteditor;
ShowAll ();
}
示例12: TestFieldSpacesBeforeComma2
public void TestFieldSpacesBeforeComma2 ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text = @"class Test {
int a , b, c;
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
policy.BeforeFieldDeclarationComma = true;
policy.AfterFieldDeclarationComma = true;
var compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstSpacingVisitor (policy, data), null);
Assert.AreEqual (@"class Test {
int a , b , c;
}", data.Document.Text);
}
示例13: 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"";
}");
}
示例14: TestIndentBlocks
public void TestIndentBlocks ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text = @"class Test {
Test TestMethod ()
{
{
{}
}
}
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.IndentBlocks = true;
var compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
Assert.AreEqual (@"class Test
{
Test TestMethod ()
{
{
{}
}
}
}", data.Document.Text);
policy.IndentBlocks = false;
compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
Assert.AreEqual (@"class Test
{
Test TestMethod ()
{
{
{}
}
}
}", data.Document.Text);
policy.IndentBlocks = false;
}
示例15: TestInvocationIndentation
public void TestInvocationIndentation ()
{
TextEditorData data = new TextEditorData ();
data.Document.FileName = "a.cs";
data.Document.Text = @"class Test {
Test TestMethod ()
{
this.TestMethod ();
}
}";
CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
policy.ClassBraceStyle = BraceStyle.EndOfLine;
var compilationUnit = new CSharpParser ().Parse (data);
compilationUnit.AcceptVisitor (new AstFormattingVisitor (policy, data), null);
Assert.AreEqual (@"class Test {
Test TestMethod ()
{
this.TestMethod ();
}
}", data.Document.Text);
}