Created
December 23, 2016 00:28
-
-
Save controlflow/ebb1bfddff12a684b06caa2e1156b4ed 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
private static void CheckUnsafeContext([NotNull] IAwaitExpression awaitExpression, [NotNull] IHighlightingConsumer consumer) | |
{ | |
for (var localFunctionDeclaration = awaitExpression.GetContainingNode<ILocalFunctionDeclaration>(); | |
localFunctionDeclaration != null; | |
localFunctionDeclaration = localFunctionDeclaration.GetContainingNode<ILocalFunctionDeclaration>()) | |
{ | |
if (localFunctionDeclaration.IsUnsafe) | |
{ | |
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression)); | |
return; | |
} | |
} | |
if (awaitExpression.GetContainingNode<IUnsafeCodeUnsafeStatement>() != null) | |
{ | |
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression)); | |
return; | |
} | |
var memberDeclaration = awaitExpression.GetContainingNode<ICSharpTypeMemberDeclaration>(returnThis: true); | |
if (memberDeclaration == null) return; | |
if (memberDeclaration.IsUnsafe) | |
{ | |
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression)); | |
return; | |
} | |
for (var typeDeclaration = memberDeclaration.GetContainingTypeDeclaration(); | |
typeDeclaration != null; | |
typeDeclaration = typeDeclaration.GetContainingTypeDeclaration()) | |
{ | |
if (typeDeclaration.IsUnsafe) | |
{ | |
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression)); | |
return; | |
} | |
} | |
} |
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
private static void CheckUnsafeContext([NotNull] IAwaitExpression awaitExpression, [NotNull] IHighlightingConsumer consumer) | |
{ | |
foreach (var containingNode in awaitExpression.ContainingNodes()) | |
{ | |
switch (containingNode) | |
{ | |
case ILocalFunctionDeclaration localFunctionDeclaration when localFunctionDeclaration.IsUnsafe: | |
case IUnsafeCodeUnsafeStatement _: | |
case ICSharpTypeMemberDeclaration memberDeclaration when memberDeclaration.IsUnsafe: | |
case ICSharpTypeDeclaration typeDeclaration when typeDeclaration.IsUnsafe: | |
{ | |
consumer.AddHighlighting(new CannotAwaitInUnsafeContextError(awaitExpression)); | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment