Created
October 7, 2016 22:22
-
-
Save controlflow/89acfd4b18808f6e0c1960ba27c287a9 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
public static bool IsInContantContext([NotNull] this ITreeNode context) | |
{ | |
foreach (var containingNode in context.ContainingNodes()) | |
{ | |
switch (containingNode) | |
{ | |
case IAttribute attribute: | |
case IConstantDeclaration constant: | |
case ILocalConstantDeclaration localConstant: | |
case IEnumMemberDeclaration enumMember: | |
case ISwitchLabelStatement switchLabel: | |
case IGotoCaseStatement gotoCase: | |
return true; | |
case IInterpolatedStringInsert insert: | |
var alignmentExpression = insert.AlignmentExpression; | |
if (alignmentExpression != null && alignmentExpression.Contains(context)) | |
return true; | |
break; | |
} | |
} | |
return false; | |
} |
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
public static bool IsInContantContext([NotNull] this ITreeNode context) | |
{ | |
foreach (var containingNode in context.ContainingNodes()) | |
{ | |
if (containingNode is IAttribute) return true; | |
if (containingNode is IConstantDeclaration) return true; | |
if (containingNode is ILocalConstantDeclaration) return true; | |
if (containingNode is IEnumMemberDeclaration) return true; | |
if (containingNode is ISwitchLabelStatement) return true; | |
if (containingNode is IGotoCaseStatement) return true; | |
var interpolatedStringInsert = containingNode as IInterpolatedStringInsert; | |
if (interpolatedStringInsert != null) | |
{ | |
var alignmentExpression = interpolatedStringInsert.AlignmentExpression; | |
if (alignmentExpression != null && alignmentExpression.Contains(context)) | |
{ | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment