public void ParameterizedMethodTypes() { string code = @" class A<T> { } class C { } class B { public A<C> f(A<C> a) { var a = new A<C>(); return a; } } "; SyntaxTree tree = SyntaxFactory.ParseSyntaxTree(code); var registry = new DeclarationRegistry(tree); var method = new MethodExtraction(registry, "f"); List <ITypeExtraction> returns = method.GetReturnTypes().ToList(); List <ITypeExtraction> arguments = method.GetArgumentTypes().ToList(); Assert.Equal(2, returns.Count()); Assert.Equal(1, returns.Where(rtrn => rtrn.Name == "A").Count()); Assert.Equal(1, returns.Where(rtrn => rtrn.Name == "C").Count()); Assert.Equal(2, arguments.Count()); Assert.Equal(1, arguments.Where(arg => arg.Name == "A").Count()); Assert.Equal(1, arguments.Where(arg => arg.Name == "C").Count()); }
public void MethodTypes() { string code = @" class A { public B f(C c) { return new B(); } } class B { } struct C { } "; SyntaxTree tree = SyntaxFactory.ParseSyntaxTree(code); var registry = new DeclarationRegistry(tree); var method = new MethodExtraction(registry, "f"); ITypeExtraction b = method.GetReturnTypes().First(); ITypeExtraction c = method.GetArgumentTypes().First(); Assert.True(b is ClassExtraction); Assert.True(c is StructExtraction); }