当前位置: 首页>>代码示例>>C#>>正文


C# Parser.CSharpParser类代码示例

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


CSharpParser类属于MonoDevelop.CSharp.Parser命名空间,在下文中一共展示了CSharpParser类的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);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:34,代码来源:TestBraceStlye.cs

示例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);
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:27,代码来源:TestTypeLevelIndentation.cs

示例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);
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:31,代码来源:TestBlankLineFormatting.cs

示例4: 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);
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:14,代码来源:TestTypeLevelIndentation.cs

示例5: Format

		public static void Format (TextEditorData data, ProjectDom dom)
		{
			CSharp.Dom.CompilationUnit compilationUnit = new MonoDevelop.CSharp.Parser.CSharpParser ().Parse (data);
			IEnumerable<string> types = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
			CSharpFormattingPolicy policy = dom.Project.Policies != null ? dom.Project.Policies.Get<CSharpFormattingPolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<CSharpFormattingPolicy> (types);
			DomSpacingVisitor domSpacingVisitor = new DomSpacingVisitor (policy, data);
			domSpacingVisitor.AutoAcceptChanges = false;
			compilationUnit.AcceptVisitor (domSpacingVisitor, null);
			
			DomIndentationVisitor domIndentationVisitor = new DomIndentationVisitor (policy, data);
			domIndentationVisitor.AutoAcceptChanges = false;
			compilationUnit.AcceptVisitor (domIndentationVisitor, null);
			
			List<Change> changes = new List<Change> ();
			changes.AddRange (domSpacingVisitor.Changes);
			changes.AddRange (domIndentationVisitor.Changes);
			RefactoringService.AcceptChanges (null, null, changes);
		}
开发者ID:silk,项目名称:monodevelop,代码行数:18,代码来源:OnTheFlyFormatter.cs

示例6: 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);
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:19,代码来源:TestSpacingVisitor.cs

示例7: Format

		public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain,
			TextEditorData data, ProjectDom dom, DomLocation location, bool correctBlankLines)
		{
			var compilationUnit = new MonoDevelop.CSharp.Parser.CSharpParser ().Parse (data);
			var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
			var domSpacingVisitor = new DomSpacingVisitor (policy, data) {
				AutoAcceptChanges = false,
			};
			compilationUnit.AcceptVisitor (domSpacingVisitor, null);
			
			var domIndentationVisitor = new DomIndentationVisitor (policy, data) {
				AutoAcceptChanges = false,
			};
			domIndentationVisitor.CorrectBlankLines = correctBlankLines;
			compilationUnit.AcceptVisitor (domIndentationVisitor, null);
			
			var changes = new List<Change> ();
			changes.AddRange (domSpacingVisitor.Changes);
			changes.AddRange (domIndentationVisitor.Changes);
			RefactoringService.AcceptChanges (null, null, changes);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:21,代码来源:OnTheFlyFormatter.cs

示例8: 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);
		}
开发者ID:raufbutt,项目名称:monodevelop-old,代码行数:23,代码来源:TestStatementIndentation.cs

示例9: TestIndentPropertyBodyIndexerCase

		public void TestIndentPropertyBodyIndexerCase ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = 
@"class Test
{
	Test this[int a] {
			get {
	return null;
}
set {
	;
}
	}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.IndentPropertyBody = true;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	Test this[int a] {
		get {
			return null;
		}
		set {
			;
		}
	}
}", data.Document.Text);
			policy.IndentPropertyBody = false;
			compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	Test this[int a] {
	get {
		return null;
	}
	set {
		;
	}
	}
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:48,代码来源:TestTypeLevelIndentation.cs

示例10: TestIndentPropertyOneLineCase2

		public void TestIndentPropertyOneLineCase2 ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = 
@"class Test
{
	Test TestMe {      get { ; }set{;}                  }
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.PropertyFormatting = PropertyFormatting.AllowOneLine;
			policy.AllowPropertyGetBlockInline = true;
			policy.AllowPropertySetBlockInline = true;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	Test TestMe { get { ; } set { ; } }
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:22,代码来源:TestTypeLevelIndentation.cs

示例11: TestIndentMethodBodyOperatorCase

		public void TestIndentMethodBodyOperatorCase ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = 
@"class Test
{
	static Test operator+(Test left, Test right)
	{
;
								;
	}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.IndentMethodBody = true;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	static Test operator+(Test left, Test right)
	{
		;
		;
	}
}", data.Document.Text);
			policy.IndentMethodBody = false;
			compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	static Test operator+(Test left, Test right)
	{
	;
	;
	}
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:39,代码来源:TestTypeLevelIndentation.cs

示例12: Format

		public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, ProjectDom dom, DomLocation location, bool correctBlankLines, bool runAferCR = false)
		{
			if (data.ParsedDocument == null || data.ParsedDocument.CompilationUnit == null)
				return;
			var member = data.ParsedDocument.CompilationUnit.GetMemberAt (location.Line + (runAferCR ? -1 : 0), location.Column);
			if (member == null || member.Location.IsEmpty || member.BodyRegion.End.IsEmpty)
				return;
			
			StringBuilder sb = new StringBuilder ();
			int closingBrackets = 0;
			DomRegion validRegion = DomRegion.Empty;
			foreach (var u in data.ParsedDocument.CompilationUnit.Usings.Where (us => us.IsFromNamespace)) {
				// the dom parser breaks A.B.C into 3 namespaces with the same region, this is filtered here
				if (u.ValidRegion == validRegion)
					continue;
				validRegion = u.ValidRegion;
				sb.Append ("namespace Stub {");
				closingBrackets++;
			}
			
			var parent = member.DeclaringType;
			while (parent != null) {
				sb.Append ("class Stub {");
				closingBrackets++;
				parent = parent.DeclaringType;
			}
			sb.AppendLine ();
			int startOffset = sb.Length;
			sb.Append (data.Editor.GetTextBetween (member.Location.Line, 1, member.BodyRegion.End.Line + (runAferCR ? 1 : 0), member.BodyRegion.End.Column));
			int endOffset = sb.Length;
			sb.AppendLine ();
			sb.Append (new string ('}', closingBrackets));

			TextEditorData stubData = new TextEditorData () { Text = sb.ToString () };
			stubData.Document.FileName = data.FileName;
			var compilationUnit = new MonoDevelop.CSharp.Parser.CSharpParser ().Parse (stubData);

			var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
			var domSpacingVisitor = new AstSpacingVisitor (policy, stubData) {
				AutoAcceptChanges = false,
			};
			compilationUnit.AcceptVisitor (domSpacingVisitor, null);

			var domIndentationVisitor = new AstIndentationVisitor (policy, stubData) {
				AutoAcceptChanges = false,
			};
			domIndentationVisitor.CorrectBlankLines = correctBlankLines;
			compilationUnit.AcceptVisitor (domIndentationVisitor, null);

			var changes = new List<Change> ();
			changes.AddRange (domSpacingVisitor.Changes.Cast<TextReplaceChange> ().Where (c => startOffset < c.Offset && c.Offset < endOffset));
			changes.AddRange (domIndentationVisitor.Changes.Cast<TextReplaceChange> ().Where (c => startOffset < c.Offset && c.Offset < endOffset));
			int delta = data.Editor.LocationToOffset (member.Location.Line, 1) - startOffset;
			HashSet<int> lines = new HashSet<int> ();
			foreach (TextReplaceChange change in changes) {
				if (change is AstSpacingVisitor.MyTextReplaceChange) 
					((AstSpacingVisitor.MyTextReplaceChange)change).SetTextEditorData (data.Editor);
				change.Offset += delta;
				lines.Add (data.Editor.OffsetToLineNumber (change.Offset));
			}
			RefactoringService.AcceptChanges (null, null, changes);
			foreach (int line in lines)
				data.Editor.Document.CommitLineUpdate (line);
			stubData.Dispose ();
		}
开发者ID:famousthom,项目名称:monodevelop,代码行数:65,代码来源:OnTheFlyFormatter.cs

示例13: TestAllowEventRemoveBlockInline

		public void TestAllowEventRemoveBlockInline ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = @"class Test
{
	public event EventHandler Handler {
		add { ; }
		remove { ; }
	}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.AllowEventAddBlockInline = false;
			policy.AllowEventRemoveBlockInline = true;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			
			Console.WriteLine (data.Document.Text);
			Assert.AreEqual (@"class Test
{
	public event EventHandler Handler {
		add {
			;
		}
		remove { ; }
	}
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:30,代码来源:TestBraceStlye.cs

示例14: TestPropertySetBraceStyle

		public void TestPropertySetBraceStyle ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = @"class Test
{
	Test A {
		get;
		set {
			;
		}
	}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.PropertySetBraceStyle = BraceStyle.NextLine;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			
			Console.WriteLine (data.Document.Text);
			Assert.AreEqual (@"class Test
{
	Test A {
		get;
		set
		{
			;
		}
	}
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:32,代码来源:TestBraceStlye.cs

示例15: TestPropertyIndentationCase2

		public void TestPropertyIndentationCase2 ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = 
@"class Test
{
				public int Prop {
 get;
set;
}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	public int Prop {
		get;
		set;
	}
}", data.Document.Text);
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:26,代码来源:TestTypeLevelIndentation.cs


注:本文中的MonoDevelop.CSharp.Parser.CSharpParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。