Using Roslyn, the only mechanism for determining members of Visual Basic document appears to be:
var members = SyntaxTree.GetRoot().DescendantNodes().Where(node =>
node is ClassStatementSyntax ||
node is FunctionAggregationSyntax ||
node is IncompleteMemberSyntax ||
node is MethodBaseSyntax ||
node is ModuleStatementSyntax ||
node is NamespaceStatementSyntax ||
node is PropertyStatementSyntax ||
node is SubNewStatementSyntax
);
How do get the member name, StarLineNumber and EndLineNumber of each member?
Exists not only the one way to get it:
1) As you try: I willn't show this way for all of kind member (they count are huge and the logic is the similar), but only a one of them, for example
ClassStatementSyntax
:ClassStatementSyntax.Identifier.ValueText
Location
as one of ways:2) More useful way – use
SemanticModel
to get a data that you want: In this way you will need to receive semantic info only forClassStatementSyntax
,ModuleStatementSyntxt
andNamespaceStatementSyntax
, and all of their members will be received just callingGetMembers()
:But attention, when you have a partial declaration your
DeclaringSyntaxReferences
will have a couple items, so you need to filterSyntaxReference
by your currentSyntaxTree