57 references to GetAncestorOrThis
Microsoft.CodeAnalysis.CSharp.EditorFeatures (1)
Interactive\CSharpSendToInteractiveSubmissionProvider.cs (1)
93SyntaxNode? candidate = node.GetAncestorOrThis<StatementSyntax>();
Microsoft.CodeAnalysis.CSharp.Features (31)
ChangeSignature\CSharpChangeSignatureService.cs (1)
177: matchingNode.GetAncestorOrThis<InvocationExpressionSyntax>()?.ArgumentList;
Completion\KeywordRecommenders\TypeVarKeywordRecommender.cs (3)
22var type = typeParameters.GetAncestorOrThis<TypeDeclarationSyntax>(); 29var @delegate = typeParameters.GetAncestorOrThis<DelegateDeclarationSyntax>(); 35var method = typeParameters.GetAncestorOrThis<MethodDeclarationSyntax>();
Completion\KeywordRecommenders\WhereKeywordRecommender.cs (1)
43var decl = typeParameters.GetAncestorOrThis<TypeDeclarationSyntax>();
ConvertLinq\CSharpConvertLinqQueryToForEachProvider.cs (2)
382var parentStatement = invocationExpression.GetAncestorOrThis<StatementSyntax>(); 534var parentStatement = _source.GetAncestorOrThis<StatementSyntax>();
Debugging\CSharpProximityExpressionsService.Worker.cs (2)
56if (_parentStatement.GetAncestorOrThis<AccessorDeclarationSyntax>() is (kind: 69var memberDeclaration = _parentStatement.GetAncestorOrThis<MemberDeclarationSyntax>();
Debugging\LocationInfoGetter.cs (1)
62var accessor = memberDeclaration.GetAncestorOrThis<AccessorDeclarationSyntax>();
ExtractMethod\CSharpSelectionResult.ExpressionResult.cs (2)
41var scope = firstToken.GetCommonRoot(lastToken).GetAncestorOrThis<ExpressionSyntax>(); 59var variableDeclExpression = node.GetAncestorOrThis<VariableDeclarationSyntax>();
GenerateType\CSharpGenerateTypeService.cs (1)
133var usingDirectiveSyntax = simpleName.GetAncestorOrThis<UsingDirectiveSyntax>();
InitializeParameter\CSharpInitializeMemberFromPrimaryConstructorParameterCodeRefactoringProvider_Update.cs (1)
104var preferredTypeDeclaration = siblingSyntax?.GetAncestorOrThis<TypeDeclarationSyntax>() ?? typeDeclaration;
IntroduceVariable\CSharpIntroduceVariableService.cs (7)
47.GetAncestorOrThis<VariableDeclaratorSyntax>() 48.GetAncestorOrThis<FieldDeclarationSyntax>() != null; 51=> expression.GetAncestorOrThis<EqualsValueClauseSyntax>().IsParentKind(SyntaxKind.Parameter); 54=> expression.GetAncestorOrThis<ConstructorInitializerSyntax>() != null; 57=> expression.GetAncestorOrThis<EqualsValueClauseSyntax>().IsParentKind(SyntaxKind.PropertyDeclaration); 83var attributeArgument = expression.GetAncestorOrThis<AttributeArgumentSyntax>(); 91var attributeDecl = attributeArgument.GetAncestorOrThis<AttributeListSyntax>();
IntroduceVariable\CSharpIntroduceVariableService_IntroduceField.cs (1)
31var oldTypeDeclaration = expression.GetAncestorOrThis<TypeDeclarationSyntax>();
IntroduceVariable\CSharpIntroduceVariableService_IntroduceLocal.cs (2)
327var firstAffectedStatement = block.Statements.Single(s => firstAffectedExpression.GetAncestorOrThis<StatementSyntax>()!.Contains(s)); 340var firstAffectedGlobalStatement = compilationUnit.Members.OfType<GlobalStatementSyntax>().Single(s => firstAffectedExpression.GetAncestorOrThis<GlobalStatementSyntax>()!.Contains(s));
MetadataAsSource\CSharpMetadataAsSourceService.cs (1)
135return annotatedChildren.Any(n => n.GetAncestorOrThis<AttributeSyntax>() == null);
Snippets\AbstractCSharpAutoPropertySnippetProvider.cs (1)
93return node.GetAncestorOrThis<PropertyDeclarationSyntax>();
Snippets\AbstractCSharpTypeSnippetProvider.cs (1)
93return node.GetAncestorOrThis<TTypeDeclarationSyntax>();
src\Analyzers\CSharp\Analyzers\QualifyMemberAccess\CSharpQualifyMemberAccessDiagnosticAnalyzer.cs (2)
32if (node.GetAncestorOrThis<AttributeSyntax>() != null) 35if (node.GetAncestorOrThis<ConstructorInitializerSyntax>() != null)
src\Analyzers\CSharp\CodeFixes\AddExplicitCast\CSharpAddExplicitCastCodeFixProvider.cs (2)
70if (spanNode.GetAncestorOrThis<ArgumentSyntax>() is ArgumentSyntax targetArgument 78else if (spanNode.GetAncestorOrThis<AttributeArgumentSyntax>() is AttributeArgumentSyntax targetAttributeArgument
Microsoft.CodeAnalysis.CSharp.Workspaces (12)
LanguageServices\FixAllSpanMappingService\CSharpFixAllSpanMappingService.cs (1)
33if (node.GetAncestorOrThis<GlobalStatementSyntax>() is null)
Recommendations\CSharpRecommendationServiceRunner.cs (2)
568var declarationSyntax = name.GetAncestorOrThis<BaseNamespaceDeclarationSyntax>(); 579var usingDirective = name.GetAncestorOrThis<UsingDirectiveSyntax>();
Simplification\Reducers\CSharpEscapingReducer.cs (2)
55var enclosingLambdaExpression = parent.GetAncestorOrThis<LambdaExpressionSyntax>(); 59var enclosingMethodBlock = parent.GetAncestorOrThis<MethodDeclarationSyntax>();
Simplification\Simplifiers\AbstractCSharpSimplifier.cs (2)
342var usingDirective = startNode.GetAncestorOrThis<UsingDirectiveSyntax>(); 351var @namespace = startNode.GetAncestorOrThis<BaseNamespaceDeclarationSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (2)
310return node.GetAncestorOrThis<CompilationUnitSyntax>()!.Usings 318return node.GetAncestorOrThis<CompilationUnitSyntax>()!.Externs
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\CSharpCodeGenerationService.cs (1)
540var block = token.Parent.GetAncestorOrThis<BlockSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (2)
1214var method = tokenOnLeftOfPosition.Parent.GetAncestorOrThis<MethodDeclarationSyntax>(); 1215var typeDecl = method.GetAncestorOrThis<TypeDeclarationSyntax>();
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (1)
CodeGeneration\SyntaxGeneratorTests.cs (1)
4161Generator.ReplaceNode(declC, declX.GetAncestorOrThis<VariableDeclaratorSyntax>(), VariableDeclarator("Q")),
Microsoft.CodeAnalysis.Features (8)
ExtractMethod\SelectionResult.cs (1)
103return containingScope.GetAncestorOrThis<TNode>();
ExtractMethod\SelectionValidator.cs (2)
72var commonRoot = token1.GetCommonRoot(token2).GetAncestorOrThis<TStatementSyntax>() ?? root; 146var commonRoot = token1.GetCommonRoot(token2).GetAncestorOrThis<TStatementSyntax>() ?? root;
IntroduceVariable\AbstractIntroduceVariableService.State.cs (1)
305if (Expression.GetAncestorOrThis<TTypeDeclarationSyntax>() != null)
RemoveUnusedVariable\AbstractRemoveUnusedVariableCodeFixProvider.cs (1)
124var localDeclaration = node.GetAncestorOrThis<TLocalDeclarationStatement>();
src\Analyzers\Core\CodeFixes\AddExplicitCast\AbstractAddExplicitCastCodeFixProvider.cs (1)
76var spanNode = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true).GetAncestorOrThis<TExpressionSyntax>();
src\Analyzers\Core\CodeFixes\AddExplicitCast\Fixer.cs (1)
211if (newRoot.FindNode(targetNode.Span).GetAncestorOrThis<TArgumentListSyntax>() is TArgumentListSyntax newArgumentList)
src\Analyzers\Core\CodeFixes\ImplementAbstractClass\AbstractImplementAbstractClassCodeFixProvider.cs (1)
34var classNode = token.Parent.GetAncestorOrThis<TClassNode>();
Microsoft.CodeAnalysis.Workspaces (1)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\AddImports\AbstractAddImportsService.cs (1)
199(SyntaxNode?)node.GetAncestorOrThis<TCompilationUnitSyntax>();
Microsoft.VisualStudio.LanguageServices.CSharp (3)
LanguageService\CSharpHelpContextService.cs (3)
385if (token.Parent.GetAncestorOrThis<MethodDeclarationSyntax>() != null) 390else if (token.Parent.GetAncestorOrThis<TypeDeclarationSyntax>() != null) 399text = token.Parent.GetAncestorOrThis<TypeParameterConstraintClauseSyntax>() != null