2 implementations of Parent
Microsoft.CodeAnalysis (1)
Operations\Operation.cs (1)
48public IOperation? Parent
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (1)
Semantics\CollectionExpressionTests.cs (1)
27082IOperation IOperation.Parent => throw null;
720 references to Parent
ILLink.RoslynAnalyzer (29)
DataFlow\LValueFlowCaptureProvider.cs (1)
43 assignment = flowCaptureReference.Parent as IAssignmentOperation;
IOperationExtensions.cs (26)
45 while (operation.Parent is IBinaryPatternOperation || 46 operation.Parent is INegatedPatternOperation || 47 operation.Parent is IRelationalPatternOperation) { 48 operation = operation.Parent; 51 switch (operation.Parent) { 107 if (operation.Parent is IAssignmentOperation assignmentOperation && 109 return operation.Parent.IsAnyCompoundAssignment () 112 } else if (operation.Parent is IIncrementOrDecrementOperation) { 114 } else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) { 120 } else if (operation.Parent is INameOfOperation || 121 operation.Parent is ITypeOfOperation || 122 operation.Parent is ISizeOfOperation) { 124 } else if (operation.Parent is IArgumentOperation argumentOperation) { 138 } else if (operation.Parent is IReturnOperation returnOperation) { 144 } else if (operation.Parent is IConditionalOperation conditionalOperation) { 151 } else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 153 return (reDimClauseOperation.Parent as IReDimOperation)?.Preserve == true 156 } else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) { 160 } else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation) { 161 if (variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) { 183 operation = operation?.Parent; 193 operation = operation.Parent; 204 var current = operation.Parent; 216 current = current.Parent; 254 var parent = operation.Parent; 270 parent = parent.Parent;
RequiresAnalyzerBase.cs (2)
204 var parent = operationContext.Operation.Parent; 220 parent = parent.Parent;
Metrics (37)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Metrics.Legacy (37)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Microsoft.Analyzers.Extra (7)
AsyncCallInsideUsingBlockAnalyzer.cs (2)
49if (operation.Parent == null) 54ValidateDisposable(analysisContext, disposable, operation.Parent);
CallAnalysis\Fixers\LegacyLoggingFixer.cs (1)
368if (invocationOp.Parent?.Kind == OperationKind.ConditionalAccess)
Utilities\OperationExtensions.cs (4)
19while (operationToStart.Parent != null) 21if (operationToStart.Parent == parent) 26yield return operationToStart.Parent; 27operationToStart = operationToStart.Parent;
Microsoft.AspNetCore.App.Analyzers (11)
Authorization\AddAuthorizationBuilderAnalyzer.cs (3)
179if (propertyReferenceOperation.Parent is IAssignmentOperation { Target: IPropertyReferenceOperation targetProperty } 184if (propertyReferenceOperation.Parent is IAssignmentOperation { Value: IPropertyReferenceOperation valueProperty } 225return invocation.Parent is IExpressionStatementOperation;
Http\RequestDelegateReturnTypeAnalyzer.cs (2)
31if (methodReference.Parent is { } parent && 47if (anonymousFunction.Parent is { } parent &&
RouteHandlers\DetectAmbiguousRoutes.cs (6)
62if (current.Parent is IArgumentOperation { Parent: IInvocationOperation invocationOperation } && 70if (current.Parent is IBlockOperation or ISwitchCaseOperation) 72return current.Parent; 74else if (current.Parent is IConditionalOperation or 84current = current.Parent;
Microsoft.AspNetCore.Mvc.Analyzers (2)
TagHelpersInCodeBlocksAnalyzer.cs (2)
60var parent = context.Operation.Parent; 63parent = parent.Parent;
Microsoft.AspNetCore.Mvc.Api.Analyzers (5)
ActualApiResponseMetadataFactory.cs (2)
305var parent = operation.Parent; 313parent = parent.Parent;
ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs (3)
51var parent = ifOperation.Parent; 58if (parent.Kind == OperationKind.Block && parent.Parent != null) 60parent = parent.Parent;
Microsoft.CodeAnalysis (30)
DiagnosticAnalyzer\AnalyzerDriver.cs (13)
2969if (operationBlock.Parent != null) 2971switch (operationBlock.Parent.Kind) 2975Debug.Assert(!operationBlock.Parent.IsImplicit); 2976operationsToAnalyze.Add(operationBlock.Parent); 2983Debug.Assert(operationBlock.Parent.IsImplicit); 2984Debug.Assert(operationBlock.Parent.Parent is IConstructorBodyOperation ctorBody && 2985ctorBody.Initializer == operationBlock.Parent); 2986Debug.Assert(!operationBlock.Parent.Parent.IsImplicit); 2988operationsToAnalyze.Add(operationBlock.Parent.Parent); 2993Debug.Fail($"Expected operation with kind '{operationBlock.Kind}' to be the root operation with null 'Parent', but instead it has a non-null Parent with kind '{operationBlock.Parent.Kind}'");
DiagnosticAnalyzer\AnalyzerExecutor.cs (1)
1548Debug.Assert(operation.Parent == null);
Operations\ControlFlowGraph.cs (1)
180if (operation.Parent != null)
Operations\ControlFlowGraphBuilder.cs (5)
95Debug.Assert(body.Parent == null); 3103Debug.Assert(operation.Parent != null); 3104bool isStatement = _currentStatement == operation || operation.Parent.Kind == OperationKind.ExpressionStatement; 3367bool isOnStatementLevel = _currentStatement == operation || (_currentStatement == operation.Parent && _currentStatement?.Kind == OperationKind.ExpressionStatement); 6594Debug.Assert(operation.Parent is InvocationOperation { Parent: CollectionExpressionOperation ce } && ce.HasErrors(_compilation),
Operations\ControlFlowGraphBuilder.InterpolatedStringContext.cs (2)
52IOperation? operation = placeholderOperation.Parent; 55operation = operation.Parent;
Operations\Operation.cs (1)
178Debug.Assert((object?)child.Parent == parent);
Operations\OperationExtensions.cs (5)
180return declarationOperation.Initializer ?? (declarationOperation.Parent as IVariableDeclarationOperation)?.Initializer; 336while (operation.Parent != null) 338operation = operation.Parent; 373for (IOperation current = operation; current.Parent != null; current = current.Parent)
Operations\OperationNodes.cs (2)
699Debug.Assert(statements.All(s => s.Parent != this && s.Parent!.Kind is OperationKind.Block or OperationKind.SwitchCase));
Microsoft.CodeAnalysis.Analyzers (40)
ImmutableObjectMethodAnalyzer.cs (1)
82if (invocation.Parent is not IExpressionStatementOperation || invocation.TargetMethod.ReturnsVoid)
MetaAnalyzers\DiagnosticDescriptorCreationAnalyzer.cs (1)
364switch (invocation.Parent)
MetaAnalyzers\Fixers\CompareSymbolsCorrectlyFix.cs (1)
201while (currentOperation.Parent is IConditionalAccessOperation conditionalAccess)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Microsoft.CodeAnalysis.AnalyzerUtilities (53)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
src\RoslynAnalyzers\Utilities\FlowAnalysis\Extensions\IOperationExtensions_FlowAnalysis.cs (1)
53=> flowCaptureReference.Parent is IAssignmentOperation assignment &&
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\DisposeAnalysis\DisposeAnalysis.DisposeDataFlowOperationVisitor.cs (3)
191if (operation.Parent is IInvocationOperation invocation && 340operation.Parent is IInvocationOperation invocation && 383return operation.Parent switch
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\DisposeAnalysis\DisposeAnalysisHelper.cs (1)
160operation.Parent is IArgumentOperation argument && argument.Parameter?.RefKind == RefKind.Out) &&
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ParameterValidationAnalysis\ParameterValidationAnalysis.ParameterValidationDataFlowOperationVisitor.cs (1)
161return operation.Parent switch
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\TaintedDataAnalysis.TaintedDataOperationVisitor.cs (1)
463if (operation.Parent is IInvocationOperation invocationOperation)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntityFactory.cs (1)
164if (conditionalAccessInstance.Parent is IMemberReferenceOperation memberReferenceParent)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowAnalysisResult.cs (1)
118Debug.Assert(operation.GetAncestor<IBlockOperation>(OperationKind.Block, predicate: b => b.Parent == null) == null);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowOperationVisitor.cs (6)
976=> operation.Parent is IInvocationOperation invocation && 1493var current = operation.Parent; 1500current = current.Parent; 1513var current = operation.Parent; 1520current = current.Parent; 2780var pendingArguments = _pendingArgumentsToPostProcess.ExtractAll(static (arg, operation) => arg.Parent == operation, operation);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\LValueFlowCapturesProvider.cs (1)
66operations.Single().Parent?.Kind == OperationKind.FlowCapture)
Microsoft.CodeAnalysis.BannedApiAnalyzers (37)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Microsoft.CodeAnalysis.CodeStyle (70)
src\Analyzers\Core\Analyzers\ConvertTypeofToNameof\AbstractConvertTypeOfToNameOfDiagnosticAnalyzer.cs (2)
50if (operation.Parent is not IPropertyReferenceOperation) 54var operationParent = (IPropertyReferenceOperation)operation.Parent;
src\Analyzers\Core\Analyzers\MakeFieldReadonly\AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs (2)
248return operation is { Type.IsValueType: true, Parent: IPropertyReferenceOperation } 249? IsWrittenTo(operation.Parent, owningSymbol)
src\Analyzers\Core\Analyzers\QualifyMemberAccess\AbstractQualifyMemberAccessDiagnosticAnalyzer.cs (1)
85if (context.Operation.Parent?.Kind == OperationKind.PropertySubpattern)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (8)
259if (operation is { Kind: OperationKind.None, Parent: INameOfOperation { Argument: var nameofArgument } } && 399Debug.Assert(memberReference.Parent is ICompoundAssignmentOperation compoundAssignment && 401memberReference.Parent is ICoalesceAssignmentOperation coalesceAssignment && 403memberReference.Parent is IIncrementOrDecrementOperation || 404memberReference.Parent is IReDimClauseOperation reDimClause && reDimClause.Operand == memberReference); 423if (memberReference?.Parent?.Parent is IExpressionStatementOperation && 424memberReference.Parent is not ICoalesceAssignmentOperation)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (10)
265if (operation.Parent is IVariableInitializerOperation) 274if (operation.Parent is ISimpleAssignmentOperation assignment && 285operation.Parent is IDelegateCreationOperation) 287return IsHandledDelegateCreationOrAnonymousFunctionTreeShape(operation.Parent); 320if (operation.Parent is IInvocationOperation) 325if (operation.Parent is ISimpleAssignmentOperation assignmentOperation) 353if (operation.Parent is IBinaryOperation) 393hasUnknownOperationNoneDescendant = operation.Parent is not INameOfOperation; 640if (unusedSymbolWriteOperation.Parent is IAssignmentOperation assignment && 645else if (unusedSymbolWriteOperation.Parent is IIncrementOrDecrementOperation)
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationDiagnosticAnalyzer.cs (4)
55if (interpolation.Parent is IInterpolatedStringOperation { Parent: IConversionOperation { Type: { } convertedType } conversion } && 61conversion.Parent is IArgumentOperation { Parent: IInvocationOperation invocation } &&
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (6)
66if (towardsParent && expression?.Parent is null) 72expression = towardsParent ? expression.Parent : parenthesized.Operand; 75expression = towardsParent ? expression.Parent : conversion.Operand; 174return Unwrap(interpolatedStringOperation?.Parent, towardsParent: true) is IArgumentOperation 176Parent: IInvocationOperation 191for (var current = operation; current is not null; current = current.Parent)
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForReturn\UseConditionalExpressionForReturnHelpers.cs (1)
51if (ifOperation.Parent is not IBlockOperation parentBlock)
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (1)
103if (ifOperation.Parent is not IBlockOperation containingBlock)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (24)
19=> operation.Parent is IAssignmentOperation assignmentOperation && 21assignmentOperation.Parent?.Kind == OperationKind.ObjectOrCollectionInitializer; 66while (operation.Parent is IBinaryPatternOperation or INegatedPatternOperation or IRelationalPatternOperation) 67operation = operation.Parent; 69switch (operation.Parent) 130if (operation.Parent is IAssignmentOperation assignmentOperation && 133return operation.Parent.IsAnyCompoundAssignment() 137else if (operation.Parent is ISimpleAssignmentOperation { IsRef: true } simpleAssignmentOperation && 142else if (operation.Parent is IIncrementOrDecrementOperation) 146else if (operation.Parent is IForToLoopOperation forToLoopOperation && forToLoopOperation.LoopControlVariable.Equals(operation)) 150else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 158else if (operation.Parent is INameOfOperation or ITypeOfOperation or ISizeOfOperation) 162else if (operation.Parent is IArgumentOperation argumentOperation) 179else if (operation.Parent is IReturnOperation returnOperation) 188else if (operation.Parent is IConditionalOperation conditionalOperation) 200else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 203return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 207else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 215else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation) 217if (variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 241operation = operation?.Parent; 253operation = operation.Parent; 264var current = operation.Parent; 278current = current.Parent;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\LValueFlowCaptureProvider.cs (2)
56if (flowCaptureReference.Parent is IAssignmentOperation assignment && 61var captureKind = flowCaptureReference.Parent.IsAnyCompoundAssignment() || rvalueFlowCaptureIds.Contains(flowCaptureReference.Id)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (9)
130if (operation.Parent is IFlowCaptureOperation flowCapture && 152if (operation.Parent is IIncrementOrDecrementOperation && 153operation.Parent.Parent?.Kind != OperationKind.ExpressionStatement) 163if (operation.Parent is IAssignmentOperation assignmentOperation && 191operation.Parent?.Kind != OperationKind.ExpressionStatement; 271operation.Parent is IForEachLoopOperation forEachLoop && forEachLoop.LoopControlVariable == operation || 272operation.Parent is ICatchClauseOperation catchClause && catchClause.ExceptionDeclarationOrExpression == operation) 420else if (write.Parent is ISimpleAssignmentOperation simpleAssignment)
Microsoft.CodeAnalysis.CodeStyle.Fixes (2)
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForAssignment\AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs (2)
114if (assignmentOperation.Parent is IConditionalAccessOperation conditionalAccess) 196if (ifOperation.Parent is not IBlockOperation parentBlock)
Microsoft.CodeAnalysis.CSharp.CodeStyle (22)
src\Analyzers\CSharp\Analyzers\MakeStructMemberReadOnly\CSharpMakeStructMemberReadOnlyAnalyzer.cs (3)
283for (var operation = instanceOperation.Parent; operation != null; operation = operation.Parent) 324if (operation.Parent is IEventAssignmentOperation)
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (1)
78=> expressionStatementOperation.Parent is IBlockOperation blockOperation &&
src\Analyzers\CSharp\Analyzers\SimplifyLinqExpression\CSharpSimplifyLinqExpressionDiagnosticAnalyzer.cs (2)
24=> invocation.Parent is IArgumentOperation { Parent: IInvocationOperation nextInvocation } ? nextInvocation : null;
src\Analyzers\CSharp\Analyzers\UseCollectionExpression\UseCollectionExpressionHelpers.cs (1)
138if (operation?.Parent is IAssignmentOperation { Type.TypeKind: TypeKind.Dynamic })
src\Analyzers\CSharp\Analyzers\UseConditionalExpression\CSharpUseConditionalExpressionForReturnDiagnosticAnalyzer.cs (1)
36if (statement is not IReturnOperation { Parent: IBlockOperation block })
src\Analyzers\CSharp\Analyzers\UseSystemThreadingLock\CSharpUseSystemThreadingLockDiagnosticAnalyzer.cs (3)
181if (fieldReferenceOperation.Parent is ILockOperation lockOperation) 200if (fieldReferenceOperation.Parent is IAssignmentOperation assignment && 208if (fieldReferenceOperation.Parent is INameOfOperation)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (11)
91Parent.Kind: OperationKind.DelegateCreation, 95var current = castExpressionOperation.Parent.Parent; 97current = current.Parent; 106if (current.Parent is IConversionOperation { Type: { } parentConversionType, IsImplicit: false } && 266if (rewrittenOperation.Parent is not IDelegateCreationOperation rewrittenDelegateCreationOperation) 277if (originalDelegateCreationOperation.Parent is IConversionOperation conversionOperation && 404if (originalConversionOperation.Parent is IConversionOperation { Conversion.IsUserDefined: true } originalParentConversionOperation) 746if (originalConversionOperation.Parent is not IConversionOperation outerOriginalConversionOperation) 799if (rewrittenOperation.Parent is not IConversionOperation rewrittenBitwiseNotConversionOperation) 895if (rewrittenConditionalOperation.Parent is IConversionOperation conditionalParentConversion &&
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (1)
src\Analyzers\CSharp\CodeFixes\UseUtf8StringLiteral\UseUtf8StringLiteralCodeFixProvider.cs (1)
133operation = operation.Parent!;
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (5)
CodeGen\CodeGenLocalFunctionTests.cs (5)
161Assert.Equal(OperationKind.ExpressionStatement, objectCreationOperation.Parent.Kind); 162Assert.Equal(OperationKind.Block, objectCreationOperation.Parent.Parent.Kind); 163Assert.Same(localFunctionOperation.IgnoredBody, objectCreationOperation.Parent.Parent);
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (40)
Semantics\OutVarTests.cs (22)
3516Assert.Null(initializerOperation.Parent.Parent.Parent); 3517VerifyOperationTree(compilation, initializerOperation.Parent.Parent, @" 35999Assert.Equal(OperationKind.ExpressionStatement, initializerOperation.Parent.Kind); 36022Assert.Equal(OperationKind.ConstructorBody, blockBodyOperation.Parent.Kind); 36023Assert.Same(initializerOperation.Parent.Parent, blockBodyOperation.Parent); 36024Assert.Null(blockBodyOperation.Parent.Parent); 36047Assert.Same(blockBodyOperation.Parent, model.GetOperation(expressionBodySyntax).Parent); 36051Assert.Same(blockBodyOperation.Parent, model.GetOperation(declarationSyntax)); 36143Assert.Equal(OperationKind.MethodBody, expressionBodyOperation.Parent.Kind); 36144Assert.Null(expressionBodyOperation.Parent.Parent); 36168Assert.Same(expressionBodyOperation.Parent, blockBodyOperation.Parent); 36176Assert.Same(expressionBodyOperation.Parent, model.GetOperation(declarationSyntax)); 36250Assert.Null(model.GetOperation(node3).Parent);
Semantics\PrimaryConstructorTests.cs (9)
1130Assert.Same(operation.Parent.Parent, model.GetOperation(baseWithargs.Parent.Parent)); 1133VerifyOperationTree(comp, operation.Parent.Parent, 1157Assert.Null(operation.Parent.Parent.Parent); 1158VerifyFlowGraph(comp, operation.Parent.Parent.Syntax, @"
Semantics\RecordTests.cs (9)
21307Assert.Same(operation.Parent.Parent, model.GetOperation(baseWithargs.Parent.Parent)); 21310VerifyOperationTree(comp, operation.Parent.Parent, 21334Assert.Null(operation.Parent.Parent.Parent); 21335VerifyFlowGraph(comp, operation.Parent.Parent.Syntax, @"
Microsoft.CodeAnalysis.CSharp.EndToEnd.UnitTests (2)
EndToEndTests.cs (2)
885for (; operation.Parent is not null; operation = operation.Parent) { }
Microsoft.CodeAnalysis.CSharp.Features (12)
src\Analyzers\CSharp\Analyzers\MakeStructMemberReadOnly\CSharpMakeStructMemberReadOnlyAnalyzer.cs (3)
283for (var operation = instanceOperation.Parent; operation != null; operation = operation.Parent) 324if (operation.Parent is IEventAssignmentOperation)
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (1)
78=> expressionStatementOperation.Parent is IBlockOperation blockOperation &&
src\Analyzers\CSharp\Analyzers\SimplifyLinqExpression\CSharpSimplifyLinqExpressionDiagnosticAnalyzer.cs (2)
24=> invocation.Parent is IArgumentOperation { Parent: IInvocationOperation nextInvocation } ? nextInvocation : null;
src\Analyzers\CSharp\Analyzers\UseCollectionExpression\UseCollectionExpressionHelpers.cs (1)
138if (operation?.Parent is IAssignmentOperation { Type.TypeKind: TypeKind.Dynamic })
src\Analyzers\CSharp\Analyzers\UseConditionalExpression\CSharpUseConditionalExpressionForReturnDiagnosticAnalyzer.cs (1)
36if (statement is not IReturnOperation { Parent: IBlockOperation block })
src\Analyzers\CSharp\Analyzers\UseSystemThreadingLock\CSharpUseSystemThreadingLockDiagnosticAnalyzer.cs (3)
181if (fieldReferenceOperation.Parent is ILockOperation lockOperation) 200if (fieldReferenceOperation.Parent is IAssignmentOperation assignment && 208if (fieldReferenceOperation.Parent is INameOfOperation)
src\Analyzers\CSharp\CodeFixes\UseUtf8StringLiteral\UseUtf8StringLiteralCodeFixProvider.cs (1)
133operation = operation.Parent!;
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (1)
Diagnostics\Suppression\RemoveUnnecessaryPragmaSuppressionsTests.cs (1)
82if (localReference.Parent is ISimpleAssignmentOperation simpleAssignment &&
Microsoft.CodeAnalysis.CSharp.IOperation.UnitTests (3)
IOperation\IOperationTests.cs (3)
514Assert.Null(operation.Parent); 687if (operation.Parent == null) 694operation = operation.Parent;
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (8)
Semantics\TopLevelStatementsTests.cs (8)
204Assert.NotNull(ControlFlowGraph.Create((IMethodBodyOperation)((IBlockOperation)operation1.Parent.Parent).Parent)); 332Assert.NotNull(ControlFlowGraph.Create((IMethodBodyOperation)((IBlockOperation)operation1.Parent.Parent).Parent)); 370Assert.NotNull(ControlFlowGraph.Create((IMethodBodyOperation)((IBlockOperation)operation2.Parent).Parent));
Microsoft.CodeAnalysis.CSharp.Test.Utilities (1)
CompilationTestUtils.cs (1)
376if (iop is { Parent: IConversionOperation parentConversion })
Microsoft.CodeAnalysis.CSharp.Workspaces (11)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (11)
91Parent.Kind: OperationKind.DelegateCreation, 95var current = castExpressionOperation.Parent.Parent; 97current = current.Parent; 106if (current.Parent is IConversionOperation { Type: { } parentConversionType, IsImplicit: false } && 266if (rewrittenOperation.Parent is not IDelegateCreationOperation rewrittenDelegateCreationOperation) 277if (originalDelegateCreationOperation.Parent is IConversionOperation conversionOperation && 404if (originalConversionOperation.Parent is IConversionOperation { Conversion.IsUserDefined: true } originalParentConversionOperation) 746if (originalConversionOperation.Parent is not IConversionOperation outerOriginalConversionOperation) 799if (rewrittenOperation.Parent is not IConversionOperation rewrittenBitwiseNotConversionOperation) 895if (rewrittenConditionalOperation.Parent is IConversionOperation conditionalParentConversion &&
Microsoft.CodeAnalysis.Features (39)
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.cs (1)
87if (ifOperation is not IConditionalOperation { Parent: IBlockOperation parentBlock })
src\Analyzers\Core\Analyzers\ConvertTypeofToNameof\AbstractConvertTypeOfToNameOfDiagnosticAnalyzer.cs (2)
50if (operation.Parent is not IPropertyReferenceOperation) 54var operationParent = (IPropertyReferenceOperation)operation.Parent;
src\Analyzers\Core\Analyzers\MakeFieldReadonly\AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs (2)
248return operation is { Type.IsValueType: true, Parent: IPropertyReferenceOperation } 249? IsWrittenTo(operation.Parent, owningSymbol)
src\Analyzers\Core\Analyzers\QualifyMemberAccess\AbstractQualifyMemberAccessDiagnosticAnalyzer.cs (1)
85if (context.Operation.Parent?.Kind == OperationKind.PropertySubpattern)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (8)
259if (operation is { Kind: OperationKind.None, Parent: INameOfOperation { Argument: var nameofArgument } } && 399Debug.Assert(memberReference.Parent is ICompoundAssignmentOperation compoundAssignment && 401memberReference.Parent is ICoalesceAssignmentOperation coalesceAssignment && 403memberReference.Parent is IIncrementOrDecrementOperation || 404memberReference.Parent is IReDimClauseOperation reDimClause && reDimClause.Operand == memberReference); 423if (memberReference?.Parent?.Parent is IExpressionStatementOperation && 424memberReference.Parent is not ICoalesceAssignmentOperation)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (10)
265if (operation.Parent is IVariableInitializerOperation) 274if (operation.Parent is ISimpleAssignmentOperation assignment && 285operation.Parent is IDelegateCreationOperation) 287return IsHandledDelegateCreationOrAnonymousFunctionTreeShape(operation.Parent); 320if (operation.Parent is IInvocationOperation) 325if (operation.Parent is ISimpleAssignmentOperation assignmentOperation) 353if (operation.Parent is IBinaryOperation) 393hasUnknownOperationNoneDescendant = operation.Parent is not INameOfOperation; 640if (unusedSymbolWriteOperation.Parent is IAssignmentOperation assignment && 645else if (unusedSymbolWriteOperation.Parent is IIncrementOrDecrementOperation)
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationDiagnosticAnalyzer.cs (4)
55if (interpolation.Parent is IInterpolatedStringOperation { Parent: IConversionOperation { Type: { } convertedType } conversion } && 61conversion.Parent is IArgumentOperation { Parent: IInvocationOperation invocation } &&
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (6)
66if (towardsParent && expression?.Parent is null) 72expression = towardsParent ? expression.Parent : parenthesized.Operand; 75expression = towardsParent ? expression.Parent : conversion.Operand; 174return Unwrap(interpolatedStringOperation?.Parent, towardsParent: true) is IArgumentOperation 176Parent: IInvocationOperation 191for (var current = operation; current is not null; current = current.Parent)
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForReturn\UseConditionalExpressionForReturnHelpers.cs (1)
51if (ifOperation.Parent is not IBlockOperation parentBlock)
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (1)
103if (ifOperation.Parent is not IBlockOperation containingBlock)
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForAssignment\AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs (2)
114if (assignmentOperation.Parent is IConditionalAccessOperation conditionalAccess) 196if (ifOperation.Parent is not IBlockOperation parentBlock)
ValueTracking\ValueTracker.OperationCollector.cs (1)
289operation = operation.Parent;
Microsoft.CodeAnalysis.ResxSourceGenerator (37)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Microsoft.CodeAnalysis.Test.Utilities (25)
CommonTestBase.cs (1)
585Assert.Equal(child.Parent, parent);
Compilation\CompilationExtensions.cs (1)
310if (operation.Parent == null)
Compilation\ControlFlowGraphVerifier.cs (15)
34(operationRoot.Parent?.Kind == OperationKind.ConstructorBody || 35operationRoot.Parent?.Kind == OperationKind.MethodBody) ? 36operationRoot.Parent : 899containingArgument = containingArgument.Parent; 906Parent: IObjectCreationOperation 908Parent: IFlowCaptureOperation, 931Parent: IInvocationOperation 944if (reference.Parent is IBinaryOperation binOp) 996if (reference.Parent is ISimpleAssignmentOperation assignment && 1042if (operation.Parent == null && operation is IsNullOperation isNull && isNull.Operand.Kind == OperationKind.FlowCaptureReference) 1631Assert.Null(root.Parent); 1639Assert.NotNull(operation.Parent); 1893n.Parent is IPropertyReferenceOperation propertyReference && 1895propertyReference.Parent is ISimpleAssignmentOperation simpleAssignment && 1897simpleAssignment.Parent.Kind == OperationKind.AnonymousObjectCreation);
Compilation\OperationTreeVerifier.cs (2)
1040if (operation.Parent is IMemberReferenceOperation memberReference && memberReference.Instance == operation) 1044else if (operation.Parent is IInvocationOperation invocation && invocation.Instance == operation)
Compilation\TestOperationVisitor.cs (4)
56Assert.Equal(LanguageNames.CSharp, operation.Parent.Language); 184Assert.NotNull(root.Parent); 185Assert.Same(root, ((SwitchCaseOperation)root.Parent).Condition); 189Assert.Null(root.Parent);
Diagnostics\CouldHaveMoreSpecificTypeAnalyzer.cs (2)
105if (initializer.Parent is IVariableDeclaratorOperation singleVariableDeclaration) 110else if (initializer.Parent is IVariableDeclarationOperation multiVariableDeclaration)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle (1)
src\Analyzers\VisualBasic\Analyzers\SimplifyLinqExpression\VisualBasicSimplifyLinqExpressionDiagnosticAnalyzer.vb (1)
24Return TryCast(invocation.Parent, IInvocationOperation)
Microsoft.CodeAnalysis.VisualBasic.Features (1)
src\Analyzers\VisualBasic\Analyzers\SimplifyLinqExpression\VisualBasicSimplifyLinqExpressionDiagnosticAnalyzer.vb (1)
24Return TryCast(invocation.Parent, IInvocationOperation)
Microsoft.CodeAnalysis.Workspaces (37)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (24)
19=> operation.Parent is IAssignmentOperation assignmentOperation && 21assignmentOperation.Parent?.Kind == OperationKind.ObjectOrCollectionInitializer; 66while (operation.Parent is IBinaryPatternOperation or INegatedPatternOperation or IRelationalPatternOperation) 67operation = operation.Parent; 69switch (operation.Parent) 130if (operation.Parent is IAssignmentOperation assignmentOperation && 133return operation.Parent.IsAnyCompoundAssignment() 137else if (operation.Parent is ISimpleAssignmentOperation { IsRef: true } simpleAssignmentOperation && 142else if (operation.Parent is IIncrementOrDecrementOperation) 146else if (operation.Parent is IForToLoopOperation forToLoopOperation && forToLoopOperation.LoopControlVariable.Equals(operation)) 150else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 158else if (operation.Parent is INameOfOperation or ITypeOfOperation or ISizeOfOperation) 162else if (operation.Parent is IArgumentOperation argumentOperation) 179else if (operation.Parent is IReturnOperation returnOperation) 188else if (operation.Parent is IConditionalOperation conditionalOperation) 200else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 203return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 207else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 215else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation) 217if (variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 241operation = operation?.Parent; 253operation = operation.Parent; 264var current = operation.Parent; 278current = current.Parent;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\LValueFlowCaptureProvider.cs (2)
56if (flowCaptureReference.Parent is IAssignmentOperation assignment && 61var captureKind = flowCaptureReference.Parent.IsAnyCompoundAssignment() || rvalueFlowCaptureIds.Contains(flowCaptureReference.Id)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (9)
130if (operation.Parent is IFlowCaptureOperation flowCapture && 152if (operation.Parent is IIncrementOrDecrementOperation && 153operation.Parent.Parent?.Kind != OperationKind.ExpressionStatement) 163if (operation.Parent is IAssignmentOperation assignmentOperation && 191operation.Parent?.Kind != OperationKind.ExpressionStatement; 271operation.Parent is IForEachLoopOperation forEachLoop && forEachLoop.LoopControlVariable == operation || 272operation.Parent is ICatchClauseOperation catchClause && catchClause.ExceptionDeclarationOrExpression == operation) 420else if (write.Parent is ISimpleAssignmentOperation simpleAssignment)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Utilities\NullableHelpers.cs (2)
37rootOperation.Parent is not null) 39rootOperation = rootOperation.Parent;
Roslyn.Diagnostics.Analyzers (40)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
TemporaryArrayAsRefAnalyzer.cs (3)
70if (declaration is not { Parent: IVariableDeclarationOperation { Parent: IVariableDeclarationGroupOperation { Parent: IUsingOperation or IUsingDeclarationOperation } } })
Roslyn.Diagnostics.CSharp.Analyzers (2)
CSharpDoNotCapturePrimaryContructorParameters.cs (2)
49for (; rootOperation.Parent != null; rootOperation = rootOperation.Parent)
System.Private.CoreLib.Generators (1)
IntrinsicsInSystemPrivateCoreLibAnalyzer.cs (1)
506operationSearch = operationSearch.Parent;
Test.Utilities (34)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;
Text.Analyzers (37)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (2)
301if (operation.Parent != null) 303switch (operation.Parent.Kind)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (1)
261if (operationBlock != null && operationBlock.Parent == null)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (34)
199return operation.Kind == OperationKind.None && operation.Parent == null; 216currentOperation = currentOperation.Parent; 235currentOperation = currentOperation.Parent; 258ancestor = ancestor.Parent; 292ancestor = ancestor.Parent; 331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent) 433while (operation.Parent != null) 435operation = operation.Parent; 564&& operation.GetAncestor(s_LambdaAndLocalFunctionKinds)?.Parent?.Type?.OriginalDefinition is { } lambdaType 604var currentOperation = tupleOperation.Parent; 613currentOperation = currentOperation.Parent; 695while (operation.Parent is IParenthesizedOperation parenthesizedOperation) 741while (operation.Parent is IConversionOperation conversionOperation) 840while (potentialLeftSide.Parent is IParenthesizedOperation or ITupleOperation) 842potentialLeftSide = potentialLeftSide.Parent; 845return potentialLeftSide.Parent switch 943switch (operation.Parent) 1000if (operation.Parent is IAssignmentOperation assignmentOperation && 1003return operation.Parent.IsAnyCompoundAssignment() 1007else if (operation.Parent is IIncrementOrDecrementOperation) 1011else if (operation.Parent is IParenthesizedOperation parenthesizedOperation) 1019else if (operation.Parent is INameOfOperation or 1025else if (operation.Parent is IArgumentOperation argumentOperation) 1035else if (operation.Parent is IReturnOperation returnOperation) 1044else if (operation.Parent is IConditionalOperation conditionalOperation) 1056else if (operation.Parent is IReDimClauseOperation reDimClauseOperation && 1059return reDimClauseOperation.Parent is IReDimOperation { Preserve: true } 1063else if (operation.Parent is IDeclarationExpressionOperation declarationExpression) 1071else if (operation.Parent is IVariableInitializerOperation variableInitializerOperation && 1072variableInitializerOperation.Parent is IVariableDeclaratorOperation variableDeclaratorOperation) 1092operation = operation.Parent; 1106operation = operation.Parent; 1125operation = operation?.Parent; 1137operation = operation.Parent;