Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you transitition from a semantic symbol back to a syntax tree node using Roslyn?

Tags:

.net

roslyn

If I have a semantic symbol lets say a parameter coming in to a method, Can I some how go back to the syntax node of this symbol?

In the below code lets say I have a handle on the "param" Identifier in the syntax tree from the param = "TEST", I swap over to the semantic model to determine the OriginalDefinition of param which takes me to the string param in the method declaration. I now want to swap back to the syntax tree and goto the original definition node.

I was able to do this with what I would consider a hack var token = tree.Root.FindToken(origNode.Locations[0].SourceSpan.Start).Parent;

Is there a better way to do this? Perhaps something similar to the GetSemanticInfo() but for the Syntax tree?

private void DoSomething(string param)
{
  param = "TEST";
}
like image 224
Jay Avatar asked Nov 05 '22 01:11

Jay


1 Answers

There isn't anything better in the current CTP, but this is feedback that we have heard, and we have a plan to address it in the future.

like image 69
Kevin Pilch Avatar answered Nov 13 '22 01:11

Kevin Pilch