Created
January 24, 2020 20:01
-
-
Save cezarypiatek/1b20d8e64d42cc9ea21fe27a8041e610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ITypeSymbol GetRangeVariableType(SemanticModel semanticModel, IRangeVariableSymbol symbol) | |
{ | |
ITypeSymbol type = null; | |
if (!symbol.Locations.IsEmpty) | |
{ | |
var location = symbol.Locations.First(); | |
if (location.IsInSource && location.SourceTree == semanticModel.SyntaxTree) | |
{ | |
var token = location.SourceTree.GetRoot().FindToken(symbol.Locations.First().SourceSpan.Start); | |
var queryBody = GetQueryBody(token); | |
if (queryBody != null) | |
{ | |
// To heuristically determine the type of the range variable in a query | |
// clause, we speculatively bind the name of the variable in the select | |
// or group clause of the query body. | |
var identifierName = SyntaxFactory.IdentifierName(symbol.Name); | |
type = semanticModel.GetSpeculativeTypeInfo( | |
queryBody.SelectOrGroup.Span.End - 1, identifierName, SpeculativeBindingOption.BindAsExpression).Type; | |
} | |
var identifier = token.Parent as IdentifierNameSyntax; | |
if (identifier != null) | |
{ | |
type = semanticModel.GetTypeInfo(identifier).Type; | |
} | |
} | |
} | |
return type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment