Created
January 21, 2019 17:05
-
-
Save controlflow/5f28edfba288618d8a396132bd09ab43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[CanBeNull] | |
private static ITreeNode GetHighlightingNodeFromExpressionStatement([NotNull] IExpressionStatement statement) | |
{ | |
var expression = statement.Expression; | |
while (expression != null) | |
{ | |
var reference = expression as IReferenceExpression; | |
if (reference != null) | |
{ | |
expression = reference.QualifierExpression; | |
if (expression == null) | |
return reference.NameIdentifier; | |
} | |
else | |
{ | |
var invocation = expression as IInvocationExpression; | |
if (invocation != null) | |
{ | |
expression = invocation.InvokedExpression; | |
} | |
else | |
{ | |
var elementAccess = expression as IElementAccessExpression; // not converted | |
expression = elementAccess != null ? elementAccess.Operand : null; | |
} | |
} | |
} | |
return null; | |
} |
This file contains hidden or 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
[CanBeNull] | |
private static ITreeNode GetHighlightingNodeFromExpressionStatement([NotNull] IExpressionStatement statement) | |
{ | |
var expression = statement.Expression; | |
while (expression != null) | |
{ | |
expression = expression switch { | |
IReferenceExpression referenceExpression => referenceExpression.QualifierExpression ?? reference.NameIdentifier, | |
IInvocationExpression invocationExpression => invocationExpression.InvokedExpression, | |
IElementAccessExpression elementAccessExpression => elementAccessExpression.Operand, | |
_ => null | |
}; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment