How to access fields and properties using a method of one class?
I tried to browse the syntax tree, but the information is not enough, so I created a compilation and got a semantic model of the syntax tree. Now I can get property and field declarations using an extension method OfType<T>
, where T
- PropertyDeclarationSyntax
or FieldDeclarationSyntax
.
Inside the method. Body.Statements
I thought I could search for characters representing the ones I got from OfType<T>
. But it's hard for me to understand what will come of it. The syntax tree simply identifies the symbol as "Identifier", which is not very useful.
If this is not the correct way to look at it please let me know.
source to share
Use SemanticModel.GetDeclaredSymbol()
in PropertyDecalartionSyntax
or one of the VariableDeclaratorSyntax
inside FieldDefinitionSyntax
. Then use SemanticModel.GetSymbolInfo()
in ids and see if they match. (Note that you must use ISymbol.Equals
as you cannot get referential equal results.
source to share