private void AnalyzeInvocation()

in src/Microsoft.VisualStudio.Threading.Analyzers/AbstractVSTHRD105AvoidImplicitTaskSchedulerCurrentAnalyzer.cs [52:81]


        private void AnalyzeInvocation(OperationAnalysisContext context)
        {
            var operation = (IInvocationOperation)context.Operation;
            IMethodSymbol? invokeMethod = operation.TargetMethod;
            if (invokeMethod?.ContainingType.BelongsToNamespace(Namespaces.SystemThreadingTasks) ?? false)
            {
                bool reportDiagnostic = false;
                bool isContinueWith = invokeMethod.Name == nameof(Task.ContinueWith) && invokeMethod.ContainingType.Name == nameof(Task);
                bool isTaskFactoryStartNew = invokeMethod.Name == nameof(TaskFactory.StartNew) && invokeMethod.ContainingType.Name == nameof(TaskFactory);

                if (isContinueWith || isTaskFactoryStartNew)
                {
                    if (!invokeMethod.Parameters.Any(p => p.Type.Name == nameof(TaskScheduler) && p.Type.BelongsToNamespace(Namespaces.SystemThreadingTasks)))
                    {
                        reportDiagnostic |= isContinueWith;

                        // Only notice uses of TaskFactory on the static instance (since custom instances may have a non-problematic default TaskScheduler set).
                        reportDiagnostic |= isTaskFactoryStartNew
                            && operation.Instance is IPropertyReferenceOperation { Property: { } factoryProperty }
                                && factoryProperty.ContainingType.Name == Types.Task.TypeName && factoryProperty.ContainingType.BelongsToNamespace(Namespaces.SystemThreadingTasks)
                                && factoryProperty.Name == nameof(Task.Factory);
                    }
                }

                if (reportDiagnostic)
                {
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, this.LanguageUtils.IsolateMethodName(operation).GetLocation()));
                }
            }
        }