本文整理汇总了C#中NArrange.CSharp.CSharpParser类的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser类的具体用法?C# CSharpParser怎么用?C# CSharpParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpParser类属于NArrange.CSharp命名空间,在下文中一共展示了CSharpParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestAutoPropertyInitializersParseCorrectly
public void TestAutoPropertyInitializersParseCorrectly()
{
CSharpTestFile testFile = CSharpTestUtilities.GetAutoPropertyInitializersFile();
using (TextReader reader = testFile.GetReader())
{
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
elements.Should().HaveCount(1, "because there is only one namespace");
elements[0].Children.Should().HaveCount(1, "because there is 1 class in the namespace");
elements[0].Children[0].Children.Should().HaveCount(4, "because there are 4 subclasses in the class");
var customer1 = elements[0].Children[0].Children[0];
var customer2 = elements[0].Children[0].Children[1];
var customer3 = elements[0].Children[0].Children[2];
var customer4 = elements[0].Children[0].Children[3];
customer1.Children.Should().HaveCount(2, "because there are only 2 properties");
customer1.Children[0].ElementType.Should().Be(ElementType.Property);
customer1.Children[1].ElementType.Should().Be(ElementType.Property);
customer2.Children.Should().HaveCount(2, "because there are only 2 properties");
customer2.Children[0].ElementType.Should().Be(ElementType.Property);
customer2.Children[1].ElementType.Should().Be(ElementType.Property);
customer3.Children.Should().HaveCount(2, "because there is only 1 property and 1 constructor");
customer3.Children[0].ElementType.Should().Be(ElementType.Property);
customer3.Children[1].ElementType.Should().Be(ElementType.Constructor);
customer4.Children.Should().HaveCount(2, "because there are only 2 properties");
customer4.Children[0].ElementType.Should().Be(ElementType.Property);
customer4.Children[1].ElementType.Should().Be(ElementType.Property);
}
}
开发者ID:MarcStan,项目名称:NArrange,代码行数:28,代码来源:CSharp6FeatureTests.cs
示例2: ExpectedBlockCloseTest
public void ExpectedBlockCloseTest()
{
StringReader reader = new StringReader(
"namespace SampleNamespace\r\n{");
CSharpParser parser = new CSharpParser();
parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例3: ParseClassPartialUnspecifiedAccessTest
public void ParseClassPartialUnspecifiedAccessTest()
{
StringReader reader = new StringReader(
"partial class Test{}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
TypeElement typeElement = elements[0] as TypeElement;
Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
Assert.AreEqual(CodeAccess.None, typeElement.Access, "Unexpected code access.");
Assert.IsTrue(typeElement.IsPartial, "Expected a partial class.");
Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:16,代码来源:CSharpParserTests.cs
示例4: ParseUsingExpectedStatementEnd
public void ParseUsingExpectedStatementEnd()
{
StringReader reader = new StringReader(
"using System.Text");
CSharpParser parser = new CSharpParser();
parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例5: ParseClassNewConstraintOrderTest
public void ParseClassNewConstraintOrderTest()
{
StringReader reader = new StringReader(
"public class Test<T> where T : new(), IDisposable {}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例6: ParseCommentBlockTest
public void ParseCommentBlockTest()
{
StringReader reader = new StringReader(
"/*\r\n" +
" * Block comment here\r\n" +
" */\r\n");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
CommentElement commentBlockElement = elements[0] as CommentElement;
Assert.AreEqual(CommentType.Block, commentBlockElement.Type, "Element is not a CommentBlockElement.");
string[] lines = commentBlockElement.Text.Split(
new string[] { Environment.NewLine }, StringSplitOptions.None);
Assert.AreEqual(3, lines.Length, "An unexpected number of comment lines were parsed.");
Assert.AreEqual(string.Empty, lines[0], "Unexpected comment line at index 0.");
Assert.AreEqual(" * Block comment here", lines[1], "Unexpected comment line at index 1.");
Assert.AreEqual(" ", lines[2], "Unexpected comment line at index 2.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:21,代码来源:CSharpParserTests.cs
示例7: ParseUsingTest
public void ParseUsingTest()
{
StringReader reader = new StringReader(
"using System.Text;");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
UsingElement usingElement = elements[0] as UsingElement;
Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
Assert.AreEqual("System.Text", usingElement.Name, "Unexpected name.");
Assert.IsTrue(usingElement.IsMovable, "C# should support moving using directives.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:14,代码来源:CSharpParserTests.cs
示例8: ExpectedFieldEndOfStatementTest
public void ExpectedFieldEndOfStatementTest()
{
StringReader reader = new StringReader(
"namespace SampleNamespace\r\n" +
"{\r\n" +
" public class SampleClass\r\n" +
" {\r\n" +
" private string test =\r\n" +
" }\r\n" +
"}");
CSharpParser parser = new CSharpParser();
parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:14,代码来源:CSharpParserTests.cs
示例9: ParseClassUnknownTypeParameterTest
public void ParseClassUnknownTypeParameterTest()
{
StringReader reader = new StringReader(
"public class Test<T> where S : new() {}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例10: ParseClassDefinitionTest
public void ParseClassDefinitionTest()
{
CSharpParser parser = new CSharpParser();
CSharpTestFile testFile = CSharpTestUtilities.GetClassDefinitionFile();
using (TextReader reader = testFile.GetReader())
{
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.IsNotNull(elements, "Code element collection should not be null.");
Assert.AreEqual(8, elements.Count, "An unexpected number of elements were parsed.");
CommentElement commentElement = elements[0] as CommentElement;
Assert.IsNotNull(commentElement, "Expected a CommentElement.");
CommentElement commentElement1 = elements[1] as CommentElement;
Assert.IsNotNull(commentElement1, "Expected a CommentElement.");
Assert.AreEqual(" This is comment line 1", commentElement1.Text, "Unexpected comment text.");
CommentElement commentElement2 = elements[2] as CommentElement;
Assert.IsNotNull(commentElement2, "Expected a CommentElement.");
Assert.AreEqual(" This is comment line 2", commentElement2.Text, "Unexpected comment text.");
CommentElement commentElement3 = elements[3] as CommentElement;
Assert.IsNotNull(commentElement3, "Expected a CommentElement.");
Assert.AreEqual(" This is comment line 3", commentElement3.Text, "Unexpected comment text.");
UsingElement using1 = elements[4] as UsingElement;
Assert.IsNotNull(using1, "Expected a UsingElement.");
Assert.AreEqual("System", using1.Name, "Unexpected using name.");
UsingElement using2 = elements[5] as UsingElement;
Assert.IsNotNull(using2, "Expected a UsingElement.");
Assert.AreEqual("System.Collections.Generic", using2.Name, "Unexpected using name.");
UsingElement using3 = elements[6] as UsingElement;
Assert.IsNotNull(using3, "Expected a UsingElement.");
Assert.AreEqual("System.Text", using3.Name, "Unexpected using name.");
NamespaceElement namespaceElement = elements[7] as NamespaceElement;
Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");
Assert.IsNotNull(namespaceElement.Children, "Namespace Children collection should not be null.");
Assert.AreEqual(1, namespaceElement.Children.Count, "An unexpected number of namespace child elements were parsed.");
TypeElement classElement = namespaceElement.Children[0] as TypeElement;
Assert.IsNotNull(classElement, "Expected a TypeElement.");
Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");
Assert.AreEqual(3, classElement.HeaderComments.Count, "An unexpected number of class header comment lines were parsed.");
foreach (ICommentElement comment in
classElement.HeaderComments)
{
Assert.AreEqual(CommentType.XmlLine, comment.Type, "Class header comment should be an XML comment.");
}
Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected class code access level.");
}
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:58,代码来源:CSharpParserTests.cs
示例11: ParseClassEmptyParameterConstraintListTest
public void ParseClassEmptyParameterConstraintListTest()
{
StringReader reader = new StringReader(
"public class Test<T> where T : {}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例12: ParseAttributeWithAttributeCharacterTest
public void ParseAttributeWithAttributeCharacterTest()
{
StringReader reader = new StringReader(
"[assembly: AssemblyDescription(\"SampleAssembly]\")]");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
AttributeElement attributeElement = elements[0] as AttributeElement;
Assert.IsNotNull(attributeElement, "Element is not a AttributeElement.");
Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
Assert.AreEqual("\"SampleAssembly]\"", attributeElement.BodyText, "Unexpected attribute text.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:15,代码来源:CSharpParserTests.cs
示例13: ParseBodyEscapedStringTest
public void ParseBodyEscapedStringTest()
{
StringReader reader = new StringReader(
"public void DoSomething()\r\n" +
"{\r\n" +
"\tstring v = string.Empty;\r\n" +
"\tv = v.Replace(\"\\\\\\\"\", \"\\\"\"\r\n" +
"}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "Unexpected number of elements were parsed.");
MethodElement methodElement = elements[0] as MethodElement;
Assert.IsNotNull(methodElement);
Assert.IsTrue(
methodElement.BodyText.Contains("v = v.Replace(\"\\\\\\\"\", \"\\\"\""),
"Escaped string line was not found in the member body.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:20,代码来源:CSharpParserTests.cs
示例14: ParseAttributeListTest
public void ParseAttributeListTest()
{
StringReader reader = new StringReader(
"[assembly: AssemblyDescription(\"SampleAssembly\"), ComVisible(false),\tAssemblyConfiguration(\"\"), TestAttribute]");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
AttributeElement attributeElement;
attributeElement = elements[0] as AttributeElement;
Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
Assert.AreEqual("\"SampleAssembly\"", attributeElement.BodyText, "Unexpected attribute text.");
Assert.AreEqual(3, attributeElement.Children.Count, "An unexpected number of child elements were parsed.");
AttributeElement attributeChildElement = attributeElement.Children[0] as AttributeElement;
Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
Assert.AreEqual("ComVisible", attributeChildElement.Name, "Unexpected attribute name.");
Assert.AreEqual("false", attributeChildElement.BodyText, "Unexpected attribute text.");
attributeChildElement = attributeElement.Children[1] as AttributeElement;
Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
Assert.AreEqual("AssemblyConfiguration", attributeChildElement.Name, "Unexpected attribute name.");
Assert.AreEqual("\"\"", attributeChildElement.BodyText, "Unexpected attribute text.");
attributeChildElement = attributeElement.Children[2] as AttributeElement;
Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
Assert.AreEqual("TestAttribute", attributeChildElement.Name, "Unexpected attribute name.");
Assert.IsNull(attributeChildElement.BodyText, "Unexpected attribute text.");
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:37,代码来源:CSharpParserTests.cs
示例15: GetMembersTestClass
/// <summary>
/// Gets the ClassMembers test class.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>Type code element.</returns>
private static TypeElement GetMembersTestClass(TextReader reader)
{
TypeElement classElement;
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(9, elements.Count, "Unexpected number of top-level elements.");
NamespaceElement namespaceElement = elements[8] as NamespaceElement;
Assert.IsNotNull(namespaceElement, "Expected a namespace element.");
Assert.AreEqual(2, namespaceElement.Children.Count, "Unexpected number of namespace elements.");
UsingElement usingElement = namespaceElement.Children[0] as UsingElement;
Assert.IsNotNull(usingElement, "Expected a using element.");
Assert.AreEqual("System.ComponentModel", usingElement.Name, "Unexpected using element name.");
classElement = namespaceElement.Children[1] as TypeElement;
Assert.IsNotNull(classElement, "Expected a type element.");
Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class type.");
Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");
Assert.AreEqual(4, classElement.HeaderComments.Count, "Unexpected number of header comments.");
return classElement;
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:31,代码来源:CSharpParserTests.cs
示例16: ParseUTF8Test
public void ParseUTF8Test()
{
CSharpParser parser = new CSharpParser();
CSharpTestFile testFile = CSharpTestUtilities.GetUTF8File();
using (TextReader reader = testFile.GetReader())
{
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.IsNotNull(elements, "Code element collection should not be null.");
TypeElement classElement = elements[0] as TypeElement;
Assert.IsNotNull(classElement, "Expected a class element.");
Assert.AreEqual("UnicodeClass", classElement.Name, "Unexpected class name.");
Assert.AreEqual(1, classElement.Children.Count, "Unexpected number of child elements.");
RegionElement regionElement = classElement.Children[0] as RegionElement;
Assert.IsNotNull(regionElement, "Element is not a RegionElement.");
Assert.AreEqual(1, regionElement.Children.Count, "Unexpected number of child elements.");
FieldElement fieldElement = regionElement.Children[0] as FieldElement;
Assert.IsNotNull(fieldElement, "Element is not a FieldElement.");
Assert.AreEqual("val", fieldElement.Name, "Unexpected name.");
Assert.AreEqual(CodeAccess.Private, fieldElement.Access, "Unexpected code access.");
Assert.AreEqual("string", fieldElement.Type, "Unexpected member type.");
Assert.AreEqual(1, fieldElement.HeaderComments.Count, "Unexpected number of header comments.");
}
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:28,代码来源:CSharpParserTests.cs
示例17: ParseClassSimpleTest
public void ParseClassSimpleTest()
{
string[] variations =
{
"public class Test{}",
"public class Test{};",
"public class Test\r\n{\r\n}\r\n"
};
foreach (string variation in variations)
{
StringReader reader = new StringReader(variation);
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
TypeElement typeElement = elements[0] as TypeElement;
Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
}
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:24,代码来源:CSharpParserTests.cs
示例18: ParseClassExpectedTypeImplementsTest
public void ParseClassExpectedTypeImplementsTest()
{
StringReader reader = new StringReader(
"public class Test<T> where T {}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例19: ParseClassUnclosedTypeParameterConstraintTest
public void ParseClassUnclosedTypeParameterConstraintTest()
{
StringReader reader = new StringReader(
"public class Test<T> where T : IComparable<T {}");
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:8,代码来源:CSharpParserTests.cs
示例20: ParseClassImplementsGenericTest
public void ParseClassImplementsGenericTest()
{
string[] variations = new string[]
{
"public class Test : IEnumerable<string>{}",
"public class Test : IEnumerable <string>{}"
};
foreach (string variation in variations)
{
StringReader reader = new StringReader(variation);
CSharpParser parser = new CSharpParser();
ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
TypeElement typeElement = elements[0] as TypeElement;
Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
Assert.AreEqual(1, typeElement.Interfaces.Count, "Unexpected number of interface implementations.");
Assert.AreEqual("IEnumerable<string>", typeElement.Interfaces[0].Name, "Unexpected interface implementation name.");
}
}
开发者ID:samuel-weber,项目名称:NArrange,代码行数:25,代码来源:CSharpParserTests.cs
注:本文中的NArrange.CSharp.CSharpParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论