Esempio n. 1
0
        public void AnalyzeNode(SyntaxNode node, SemanticModel semanticModel, Action <Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var expr = (PrefixUnaryExpressionSyntax)node;

            var info = semanticModel.GetAwaitExpressionInfo(expr);

            if (!info.IsDynamic)
            {
                var operand = semanticModel.GetTypeInfo(expr.Operand);

                var namedType = operand.Type as INamedTypeSymbol;
                if (namedType != null)
                {
                    if (namedType.IsGenericType)
                    {
                        var symbol = semanticModel.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
                        if (namedType.ConstructedFrom == symbol)
                        {
                            addDiagnostic(Diagnostic.Create(desc, expr.GetLocation()));
                        }
                    }
                    else
                    {
                        var symbol = semanticModel.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
                        if (namedType == symbol)
                        {
                            addDiagnostic(Diagnostic.Create(desc, expr.GetLocation()));
                        }
                    }
                }
            }
        }