本文整理汇总了C#中IParser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# IParser.Parse方法的具体用法?C# IParser.Parse怎么用?C# IParser.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IParser
的用法示例。
在下文中一共展示了IParser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTestEnums
void DoTestEnums (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs",
@"enum TestEnum {
A,
B,
C
}").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Enum, type.ClassType);
Assert.AreEqual ("TestEnum", type.Name);
Assert.AreEqual (3, type.FieldCount);
foreach (IField f in type.Fields) {
Assert.IsTrue (f.IsConst);
Assert.IsTrue (f.IsSpecialName);
Assert.IsTrue (f.IsPublic);
if (f.Name == "A") {
Assert.AreEqual (2, f.Location.Line);
} else if (f.Name == "B") {
Assert.AreEqual (3, f.Location.Line);
} else if (f.Name == "C") {
Assert.AreEqual (4, f.Location.Line);
} else {
Assert.Fail ("Unknown field: " + f.Name);
}
}
}
示例2: GetResponse
public Response GetResponse(object data, string templateName, IParser parser)
{
var connection = new Connection(_authentication.ApiUrl);
var template = _templateFactory.GetInstance(templateName);
template.Authentication = _authentication;
var requestBody = template.Render(data);
var response = connection.Request("post", requestBody, null);
return parser.Parse(response);
}
示例3: setup
public void setup()
{
scanner = new ScanStrings("hello, world");
matching_parser = Substitute.For<IMatchingParser>();
complex_parser = Substitute.For<IParser>();
matching_parser.TryMatch(scanner).ReturnsForAnyArgs(new ParserMatch(null, scanner, 0, 0));
complex_parser.Parse(scanner).ReturnsForAnyArgs(new ParserMatch(null, scanner, 0, 0));
subject = new Recursion();
}
示例4: Load
private object Load(Stream stream, IParser parser)
{
try
{
xmlReader = new XmlCompatibilityReader(stream);
return parser.Parse(xmlReader);
}
catch (Exception e)
{
throw new LoadException($"Error loading XAML: {e}", xmlReader.LineNumber, xmlReader.LinePosition, e);
}
}
示例5: DoTestFields
void DoTestFields (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"class AClass { int x, y; }").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (2, type.FieldCount);
List<IField> fields = new List<IField> (type.Fields);
Assert.AreEqual ("x", fields[0].Name);
Assert.AreEqual ("System.Int32", fields[0].ReturnType.FullName);
Assert.AreEqual ("y", fields[1].Name);
Assert.AreEqual ("System.Int32", fields[1].ReturnType.FullName);
}
示例6: SetUp
public void SetUp()
{
_reportBreakerMock = new Mock<IReportBreaker>();
_nitriqReportParserMock = new Mock<IReportParser>();
_teamCityInfoBuilderMock = new Mock<ITeamCityInfoBuilder>();
_teamCityInfoXmlGeneratorMock = new Mock<ITeamCityInfoXmlGenerator>();
_documentWriterMock = new Mock<IXmlDocumentWriter>();
_parser = new Parser(_reportBreakerMock.Object,
_nitriqReportParserMock.Object,
_teamCityInfoBuilderMock.Object,
_teamCityInfoXmlGeneratorMock.Object,
_documentWriterMock.Object);
_parser.Parse("report", "output");
}
示例7: DoTestUsings
void DoTestUsings (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs",
@"using System;
using NUnit.Framework;").CompilationUnit;
foreach (IUsing u in unit.Usings) {
foreach (string ns in u.Namespaces) {
if (ns == "System") {
Assert.AreEqual (1, u.Region.End.Line);
Assert.AreEqual (1, u.Region.Start.Line);
} else if (ns == "NUnit.Framework") {
Assert.AreEqual (2, u.Region.End.Line);
Assert.AreEqual (2, u.Region.Start.Line);
} else {
Assert.Fail ("Unknown using: " + ns);
}
}
}
}
示例8: DoTestMethods
void DoTestMethods (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs",
@"class AClass {
void TestMethod<T> (string a, int b) {}
void ExtensionMethod (this int a) {};
}").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (2, type.MethodCount);
List<IMethod> methods = new List<IMethod> (type.Methods);
Assert.AreEqual ("TestMethod", methods[0].Name);
Assert.AreEqual (2, methods[0].Parameters.Count);
Assert.AreEqual ("a", methods[0].Parameters[0].Name);
Assert.AreEqual ("b", methods[0].Parameters[1].Name);
Assert.IsFalse (methods[1].IsConstructor);
Assert.IsTrue (methods[1].IsExtension);
Assert.AreEqual (1, methods[1].Parameters.Count);
Assert.AreEqual ("a", methods[1].Parameters[0].Name);
}
示例9: DoTestConstructor
void DoTestConstructor (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs",
@"public abstract class BaseClass {
BaseClass () {}
protected BaseClass(int id)
{
}
}").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (2, type.ConstructorCount);
List<IMethod> methods = new List<IMethod> (type.Methods);
Assert.IsTrue (methods[0].IsConstructor);
Assert.IsTrue (methods[1].IsConstructor);
}
示例10: DoTestAttributes
void DoTestAttributes (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"[Attr1][Attr2(1,true)][Attr3('c',a=1,b=""hi"")] public class TestClass { }").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Class, type.ClassType);
Assert.AreEqual ("TestClass", type.Name);
IEnumerator<IAttribute> e = type.Attributes.GetEnumerator ();
Assert.IsTrue (e.MoveNext ());
IAttribute att = e.Current;
Assert.AreEqual ("Attr1", att.Name);
Assert.AreEqual (0, att.PositionalArguments.Count);
Assert.AreEqual (0, att.NamedArguments.Count);
Assert.IsTrue (e.MoveNext ());
att = e.Current;
Assert.AreEqual ("Attr2", att.Name);
Assert.AreEqual (2, att.PositionalArguments.Count);
Assert.AreEqual (0, att.NamedArguments.Count);
Assert.IsTrue (att.PositionalArguments [0] is CodePrimitiveExpression);
CodePrimitiveExpression exp = (CodePrimitiveExpression) att.PositionalArguments [0];
Assert.AreEqual (1, exp.Value);
exp = (CodePrimitiveExpression) att.PositionalArguments [1];
Assert.AreEqual (true, exp.Value);
Assert.IsTrue (e.MoveNext ());
att = e.Current;
Assert.AreEqual ("Attr3", att.Name);
Assert.AreEqual (1, att.PositionalArguments.Count);
Assert.AreEqual (2, att.NamedArguments.Count);
Assert.IsTrue (att.PositionalArguments [0] is CodePrimitiveExpression);
exp = (CodePrimitiveExpression) att.PositionalArguments [0];
Assert.AreEqual ('c', exp.Value);
exp = (CodePrimitiveExpression) att.NamedArguments ["a"];
Assert.AreEqual (1, exp.Value);
exp = (CodePrimitiveExpression) att.NamedArguments ["b"];
Assert.AreEqual ("hi", exp.Value);
Assert.IsFalse (e.MoveNext ());
}
示例11: DoTestNamespace
void DoTestNamespace (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"namespace Test1.Test2.Test3 { class A { } }").CompilationUnit;
Assert.AreEqual (3, unit.Usings.Count);
Assert.AreEqual ("Test1.Test2.Test3", unit.Usings[0].Namespaces[0]);
Assert.AreEqual ("Test1.Test2", unit.Usings[1].Namespaces[0]);
Assert.AreEqual ("Test1", unit.Usings[2].Namespaces[0]);
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual ("Test1.Test2.Test3", type.Namespace);
}
示例12: DoTestClass
void DoTestClass (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"public partial class TestClass<T, S> : MyBaseClass where T : Constraint { }").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Class, type.ClassType);
Assert.AreEqual ("TestClass", type.Name);
Assert.AreEqual ("MyBaseClass", type.BaseType.Name);
Assert.AreEqual (Modifiers.Partial | Modifiers.Public, type.Modifiers);
Assert.AreEqual (2, type.TypeParameters.Count);
Assert.AreEqual ("T", type.TypeParameters[0].Name);
Assert.AreEqual ("Constraint", type.TypeParameters[0].Constraints[0].Name);
Assert.AreEqual ("S", type.TypeParameters[1].Name);
}
示例13: DoTestDelegate
void DoTestDelegate (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"delegate void TestDelegate (int a, string b);").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Delegate, type.ClassType);
Assert.AreEqual ("TestDelegate", type.Name);
foreach (IMethod method in type.Methods) {
Assert.AreEqual (DomReturnType.Void.FullName, method.ReturnType.FullName);
foreach (IParameter parameter in method.Parameters) {
if (parameter.Name == "a") {
Assert.AreEqual (DomReturnType.Int32.FullName, parameter.ReturnType.FullName);
} else if (parameter.Name == "b") {
Assert.AreEqual (DomReturnType.String.FullName, parameter.ReturnType.FullName);
} else {
Assert.Fail ("Unknown parameter: " + parameter.Name);
}
}
}
}
示例14: DoTestInterface
void DoTestInterface (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"interface TestInterface { }").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Interface, type.ClassType);
Assert.AreEqual ("TestInterface", type.Name);
}
示例15: DoTestStruct
void DoTestStruct (IParser parser)
{
ICompilationUnit unit = parser.Parse (null, "a.cs", @"struct TestStruct { }").CompilationUnit;
Assert.AreEqual (1, unit.Types.Count);
IType type = unit.Types[0];
Assert.AreEqual (ClassType.Struct, type.ClassType);
Assert.AreEqual ("TestStruct", type.Name);
}