Esempio n. 1
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.");
        }