I obtained a IMethodSymbol
object from the given SemanticModel
, but then realized the symbol lacks the reference to its declaration syntax.
Let us assume I can easily create the respect SyntaxTree
object for any symbol.
How can I "refresh" the IMethodSymbol
object?
Here is what I have so far:
IMethodSymbol methodSymbol = ...;
if (methodSymbol.DeclaringSyntaxReferences.Length == 0)
{
var syntaxTree = ...;
var compilation = semanticModel.Compilation.AddSyntaxTrees(syntaxTree);
semanticModel = compilation.GetSemanticModel(semanticModel.SyntaxTree);
methodSymbol = ???;
}
The new semanticModel
object is linked to the new compilation
object which extends the old one with the relevant syntax tree. I do not want to repeat the whole process I used to get the methodSymbol
object in the first place.
Surely I should be able to leverage the fact that I already have it from the other instance of the semantic model. But how?