コード例 #1
0
        private IInvocationExpression FindInvocationChain([NotNull] ICSharpTreeNode topLevelNode)
        {
            foreach (var invocation in topLevelNode.Descendants().OfType <IInvocationExpression>())
            {
                if (MatchChain(invocation))
                {
                    return(invocation);
                }
            }

            return(null);
        }
コード例 #2
0
        public static HashSet <Assertion> CollectAssertions(
            [NotNull] AssertionMethodAnnotationProvider assertionMethodAnnotationProvider,
            [NotNull] AssertionConditionAnnotationProvider assertionConditionAnnotationProvider,
            [NotNull] ICSharpTreeNode rootNode)
        {
            var forTypeLevelInitializersOnly = rootNode is IClassLikeDeclaration;

            var assertions = new HashSet <Assertion>();

            foreach (var expression in rootNode.Descendants <ICSharpExpression>())
            {
                Debug.Assert(expression != null);

                var isInTypeLevelInitializer = expression.PathToRoot()
                                               .Any(node => node is IExpressionInitializer && (node.Parent is IFieldDeclaration || node.Parent is IPropertyDeclaration));

                if (forTypeLevelInitializersOnly != isInTypeLevelInitializer)
                {
                    continue;
                }

                switch (expression)
                {
                case IInvocationExpression invocationExpression:
                    var assertionStatement = AssertionStatement.TryFromInvocationExpression(
                        invocationExpression,
                        assertionMethodAnnotationProvider,
                        assertionConditionAnnotationProvider);
                    if (assertionStatement != null)
                    {
                        assertions.Add(assertionStatement);
                    }

                    var inlineAssertion = InlineAssertion.TryFromInvocationExpression(invocationExpression);
                    if (inlineAssertion != null)
                    {
                        assertions.Add(inlineAssertion);
                    }
                    break;

                case ISuppressNullableWarningExpression suppressNullableWarningExpression:
                    assertions.Add(new NullForgivingOperation(suppressNullableWarningExpression));
                    break;
                }
            }

            return(assertions);
        }