/// <summary>
        /// Creates list of <see cref="LambdaExpression"/> that can be used to check method arguments.
        /// </summary>
        /// <param name="expression">Method to process</param>
        /// <returns>List of lambda</returns>
        public static IReadOnlyList <LambdaExpression> Convert(MethodCallExpression expression)
        {
            var @this = new MethodArgumentsToVerifiers(expression.Method);

            @this.Visit(expression);
            return(@this.lambdas.AsReadOnly());
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a <see cref="IMatchInfo"/> instance from the target <paramref name="expression"/>.
        /// </summary>
        /// <param name="expression">The <see cref="LambdaExpression"/> from which to create a <see cref="IMatchInfo"/> instance.</param>
        /// <returns><see cref="IMatchInfo"/>.</returns>
        public static IMatchInfo ToMatchInfo(this LambdaExpression expression)
        {
            var simplified = expression.Simplify();

            if (simplified == null)
            {
                throw new InvalidOperationException($"Simplified expression for {expression.Body.NodeType} is null");
            }
            switch (simplified.Body)
            {
            case MethodCallExpression methodCallExpression:
                return(new MethodMatchInfo(methodCallExpression.Method, MethodArgumentsToVerifiers.Convert(methodCallExpression)));

            case MemberExpression memberExpression:
                return(new MemberMatchInfo(memberExpression.Member));
            }
            throw new NotSupportedException($"Expression type ({simplified.Body.NodeType}) not supported.");
        }