Example #1
0
        public static bool TryAnalyzeVariableDeclaration(
            SemanticModel semanticModel,
            VariableDeclarationSyntax variableDeclaration,
            [NotNullWhen(true)] out INamedTypeSymbol?tupleType,
            out ImmutableArray <MemberAccessExpressionSyntax> memberAccessExpressions,
            CancellationToken cancellationToken)
        {
            tupleType = null;
            memberAccessExpressions = default;

            // Only support code of the form:
            //
            //      var t = ...;  or
            //      (T1 e1, ..., TN eN) t = ...
            if (!variableDeclaration.IsParentKind(SyntaxKind.LocalDeclarationStatement))
            {
                return(false);
            }

            if (variableDeclaration.Variables.Count != 1)
            {
                return(false);
            }

            var declarator = variableDeclaration.Variables[0];

            if (declarator.Initializer == null)
            {
                return(false);
            }

            var local = (ILocalSymbol)semanticModel.GetRequiredDeclaredSymbol(declarator, cancellationToken);

            var initializerConversion = semanticModel.GetConversion(declarator.Initializer.Value, cancellationToken);

            return(TryAnalyze(
                       semanticModel, local, variableDeclaration.Type, declarator.Identifier, initializerConversion,
                       variableDeclaration.GetRequiredParent().GetRequiredParent(), out tupleType, out memberAccessExpressions, cancellationToken));
        }