Exemple #1
0
        public static async Task <bool> CheckedInMethodContract(this ParameterSyntax parameter, SemanticModel semanticModel, CancellationToken token)
        {
            BaseMethodDeclarationSyntax method = parameter.AncestorsAndSelf().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            if (method != null)
            {
                ContractBlock contractBlock = await ContractBlock.CreateForMethodAsync(method, semanticModel, token);

                return(contractBlock.Preconditions.Any(p => p.ChecksForNotNull(parameter)));
            }

            // It seems that this parameter was declared in indexer
            var indexer = parameter.AncestorsAndSelf().OfType <IndexerDeclarationSyntax>().FirstOrDefault();

            if (indexer == null)
            {
                // That's strage!
                Contract.Assert(false, "This should never happend!! Right?");
                return(false);
            }

            return(indexer.AccessorList.Accessors.All(a =>
            {
                ContractBlock contractBlock = ContractBlock.CreateForMethodAsync(a, semanticModel, token).Result;
                return contractBlock.Preconditions.Any(p => p.ChecksForNotNull(parameter));
            }));
        }
Exemple #2
0
        public static async Task <bool> EnsuresReturnValueIsNotNull(
            this BaseMethodDeclarationSyntax method, SemanticModel semanticModel, CancellationToken token)
        {
            Contract.Requires(method != null);
            Contract.Requires(semanticModel != null);

            ContractBlock contractBlock = await ContractBlock.CreateForMethodAsync(method, semanticModel, token);

            return(contractBlock.Postconditions.Any(p => p.HasNotNullCheck()));
        }