Esempio n. 1
0
 public void MethodExecuteTest()
 {
     string sourceCode = @"class Bar { public void Foo() {} }";
     var semanticModel = CompileAndGetSymanticModel(sourceCode);
     var syntaxTree = semanticModel.SyntaxTree;
     var fooMethodSyntax = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().ToList()[0];
     var fooMethodSymbol = semanticModel.GetDeclaredSymbol(fooMethodSyntax);
     var methodSymbolInfo = new MethodQueryData(fooMethodSymbol);
     Assert.AreEqual("Foo", methodSymbolInfo.MethodName);
 }
Esempio n. 2
0
 public void HasAttributeAppliedTest()
 {
     string sourceCode = @"using System; class Bar { [Obsolete] public void Foo() { } }";
     var semanticModel = CompileAndGetSymanticModel(sourceCode);
     var syntaxTree = semanticModel.SyntaxTree;
     var fooMethodSyntax = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().ToList()[0];
     var fooMethodSymbol = semanticModel.GetDeclaredSymbol(fooMethodSyntax);
     var methodSymbolInfo = new MethodQueryData(fooMethodSymbol);
     Assert.True(methodSymbolInfo.HasAttributeApplied(typeof(ObsoleteAttribute)));
 }
Esempio n. 3
0
 public void HasParameterTypeTest()
 {
     string sourceCode = @"using System; class Bar { public int Foo(int a) { return a+1; } }";
     var semanticModel = CompileAndGetSymanticModel(sourceCode);
     var syntaxTree = semanticModel.SyntaxTree;
     var fooMethodSyntax = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().ToList()[0];
     var fooMethodSymbol = semanticModel.GetDeclaredSymbol(fooMethodSyntax);
     var methodSymbolInfo = new MethodQueryData(fooMethodSymbol);
     Assert.True(methodSymbolInfo.HasParameterType(typeof(int)));
     Assert.False(methodSymbolInfo.HasParameterType(typeof(string)));
 }
Esempio n. 4
0
 public void HasModifierTest()
 {
     string sourceCode = @"using System; class Bar { public virtual int Foo(params int[] a) { return 0; } }";
     var semanticModel = CompileAndGetSymanticModel(sourceCode);
     var syntaxTree = semanticModel.SyntaxTree;
     var fooMethodSyntax = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().ToList()[0];
     var fooMethodSymbol = semanticModel.GetDeclaredSymbol(fooMethodSyntax);
     var methodSymbolInfo = new MethodQueryData(fooMethodSymbol);
     Assert.IsTrue(methodSymbolInfo.HasModifier(MethodModifier.Virtual));
     Assert.IsFalse(methodSymbolInfo.HasModifier(MethodModifier.Protected));
 }
Esempio n. 5
0
 public void MethodReturningVoidTest()
 {
     string sourceCode = @"class Bar { public void Foo() { } }";
     var semanticModel = CompileAndGetSymanticModel(sourceCode);
     var syntaxTree = semanticModel.SyntaxTree;
     var fooMethodSyntax = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().ToList()[0];
     var fooMethodSymbol = semanticModel.GetDeclaredSymbol(fooMethodSyntax);
     var methodSymbolInfo = new MethodQueryData(fooMethodSymbol);
     Assert.True(methodSymbolInfo.ReturnsType(typeof(void)));
 }