public async Task <bool> Test_Refactoring_Availability(string method)
        {
            var doc = await ClassTemplate.FromMethodAsync(method);

            var refactoring = await AddNotNullRequiresRefactoring.Create(doc.SelectedNode, doc.SemanticModel);

            return(await refactoring.IsAvailableAsync(CancellationToken.None));
        }
        private void AnalyzeParameter(SyntaxNodeAnalysisContext context)
        {
            var enclosingMetod = context.Node.Ancestors().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            if (enclosingMetod == null || !enclosingMetod.IsPublicOrProtected())
            {
                return;
            }

            var requiresRefactoring = AddNotNullRequiresRefactoring.Create(context.Node as ParameterSyntax, context.SemanticModel, context.CancellationToken).Result;

            if (requiresRefactoring.IsAvailableAsync(context.CancellationToken).Result)
            {
                var diagnostic = Diagnostic.Create(AddRequiresRule, context.Node.GetLocation(), requiresRefactoring.Parameter.Value?.Identifier.Text);
                context.ReportDiagnostic(diagnostic);
            }
        }
Esempio n. 3
0
 internal override async Task <ICodeContractRefactoring> CreateRefactoringAsync(ClassTemplate doc)
 {
     return(await AddNotNullRequiresRefactoring.Create(doc.SelectedNode, doc.SemanticModel));
 }