コード例 #1
0
        static void Analyze([NotNull] IAnonymousMethodExpression anonymousMethodExpression, [NotNull] IHighlightingConsumer consumer)
        {
            if (!anonymousMethodExpression.IsAsync || !anonymousMethodExpression.ReturnType.IsVoid())
            {
                return; // not an "async delegate (...) { ... }" that returns void
            }

            if (anonymousMethodExpression.Parent is IAssignmentExpression assignmentExpression &&
                assignmentExpression.IsEventSubscriptionOrUnSubscription())
            {
                return; // direct event target
            }

            Debug.Assert(anonymousMethodExpression.AsyncKeyword != null);

            consumer.AddHighlighting(
                new AsyncVoidFunctionExpressionHighlighting(
                    "'async void' anonymous method expression not used as a direct event handler.",
                    anonymousMethodExpression.AsyncKeyword,
                    () => anonymousMethodExpression.SetAsync(false)));
        }