Repository: dotnet/roslyn
File: src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs (C#)

Code before:
            }

            if (char.IsLower(name[0]) && !semanticDocument.SemanticModel.Compilation.IsCaseSensitive)
            {
                // It's near universal in .NET that types start with a capital letter.  As such,
                // if this name starts with a lowercase letter, don't even bother to offer 
                // "generate type".  The user most likely wants to run 'Add Import' (which will
                // then fix up a case where they typed an existing type name in lowercase, 
                // intending the fix to case correct it).
                return false;
            }

            Contract.ThrowIfNull(generateTypeServiceStateOptions.NameOrMemberAccessExpression);
            NameOrMemberAccessExpression = generateTypeServiceStateOptions.NameOrMemberAccessExpression;
            ObjectCreationExpressionOpt = generateTypeServiceStateOptions.ObjectCreationExpressionOpt;

            var semanticModel = semanticDocument.SemanticModel;
            var info = semanticModel.GetSymbolInfo(SimpleName, cancellationToken);
            if (info.Symbol != null)
            {
                // This bound, so no need to generate anything.
                return false;
            }

            var semanticFacts = semanticDocument.Document.GetRequiredLanguageService<ISemanticFactsService>();
            if (!generateTypeServiceStateOptions.IsInDocCommentContext &&
                !semanticFacts.IsTypeContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsExpressionContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsStatementContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsInsideNameOfExpression(semanticModel, NameOrMemberAccessExpression, cancellationToken) &&
                !semanticFacts.IsNamespaceContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken))
            {
                return false;
            }

            // If this isn't something that can be created, then don't bother offering to create
            // it.
            if (info.CandidateReason == CandidateReason.NotCreatable)
            {
                return false;
            }

            if (info.CandidateReason is CandidateReason.Inaccessible or
                CandidateReason.NotReferencable or
                CandidateReason.OverloadResolutionFailure)
            {
                // We bound to something inaccessible, or overload resolution on a 
                // constructor call failed.  Don't want to offer GenerateType here.
                return false;
            }


Review comment (suggestion):
Rather than having to check this specifically, it looks like we already have the node? Can we just ask if that's inside doc comment trivia? SyntaxFacts might already have the method you need. It's not a huge deal, but just avoids having to pass around the extra boolean.

Code after:
            }

            if (char.IsLower(name[0]) && !semanticDocument.SemanticModel.Compilation.IsCaseSensitive)
            {
                // It's near universal in .NET that types start with a capital letter.  As such,
                // if this name starts with a lowercase letter, don't even bother to offer 
                // "generate type".  The user most likely wants to run 'Add Import' (which will
                // then fix up a case where they typed an existing type name in lowercase, 
                // intending the fix to case correct it).
                return false;
            }

            Contract.ThrowIfNull(generateTypeServiceStateOptions.NameOrMemberAccessExpression);
            NameOrMemberAccessExpression = generateTypeServiceStateOptions.NameOrMemberAccessExpression;
            ObjectCreationExpressionOpt = generateTypeServiceStateOptions.ObjectCreationExpressionOpt;

            var semanticModel = semanticDocument.SemanticModel;
            var info = semanticModel.GetSymbolInfo(SimpleName, cancellationToken);
            if (info.Symbol != null)
            {
                // This bound, so no need to generate anything.
                return false;
            }

            var semanticFacts = semanticDocument.Document.GetRequiredLanguageService<ISemanticFactsService>();
            if (!IsInsideDocumentationComment(NameOrMemberAccessExpression, syntaxFacts) &&
                !semanticFacts.IsTypeContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsExpressionContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsStatementContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken) &&
                !semanticFacts.IsInsideNameOfExpression(semanticModel, NameOrMemberAccessExpression, cancellationToken) &&
                !semanticFacts.IsNamespaceContext(semanticModel, NameOrMemberAccessExpression.SpanStart, cancellationToken))
            {
                return false;
            }

            // If this isn't something that can be created, then don't bother offering to create
            // it.
            if (info.CandidateReason == CandidateReason.NotCreatable)
            {
                return false;
            }

            if (info.CandidateReason is CandidateReason.Inaccessible or
                CandidateReason.NotReferencable or
                CandidateReason.OverloadResolutionFailure)
            {
                // We bound to something inaccessible, or overload resolution on a 
                // constructor call failed.  Don't want to offer GenerateType here.
                return false;
            }