You are looking at the abstract syntax tree (AST) level of code. Hence line:
returnType.DescendantNodes().OfType<PropertyDeclarationSyntax>();
returns nothing. returnType
in this context is IdentifierNameSyntax
node of the AST, just containing text FooObject
. If you want to analyze return type, you should:
- interpret syntax tree from
returnType
point of view to find full namespace of the return type - search trough code to find this type declaration
- analyze type declaration syntax tree to find all its properties
But, it is in fact what compiler does so you can go level up with Roslyn usage to the compilation level, for example:
var workspace = Workspace.LoadSolution(solutionName);
var solution = workspace.CurrentSolution;
var createCommandList = new List<ISymbol>();
var @class = solution.Projects.Select(s => s.GetCompilation()
.GetTypeByMetadataName(className))
.FirstOrDefault();
var method = @class.GetMembers(methodName)
.AsList()
.Where(s => s.Kind == CommonSymbolKind.Method)
.Cast<MethodSymbol>()
.FirstOrDefault();
var returnType = method.ReturnType as TypeSymbol;
var returnTypeProperties = returnType.GetMembers()
.AsList()
.Where(s => s.Kind == SymbolKind.Property)
.Select(s => s.Name);