I am new to Roslyn. I am wondering if there is a way to determine if a variable is in scope at some position in the semantic model. To give some information about what I'm doing, I am trying to convert blocks foreachthat iterate over the results Select, for example. kind of
foreach (string str in new int[0].Select(i => i.ToString()))
{
}
to
foreach (int item in new int[0])
{
string str = item.ToString();
}
Here is the relevant part of my code fix provider. I am currently hard-coded for an iteration variable item:
var ident = SyntaxFactory.Identifier("item");
Then I extract the Bodyselector SimpleLambdaExpressionSyntaxand (in the case above), replacing the parameter iwith item, to get item.ToString():
var paramTokens = from token in selectorBody.DescendantTokens()
where token.Text == selectorParam.Identifier.Text
select token;
selectorBody = selectorBody.ReplaceTokens(paramTokens, (_, __) => ident);
, , item foreach, . - SemanticModel/Symbol/etc. API-?
.