예제 #1
0
        public static IArgumentMatcher Create(Expression expression)
        {
            switch (expression.NodeType)
            {
            case ExpressionType.Call:
                var call = (MethodCallExpression)expression;

                // Check if the MethodCallExpression is a With-expression
                using (var context = new MatchingContext())
                {
                    Expression.Lambda <Action>(call).Compile()();

                    if (context.LastMatcher != null)
                    {
                        return(new WithExpressionMatcher(context.LastMatcher));
                    }
                }

                break;

            case ExpressionType.Constant:
                return(new ConstantMatcher(((ConstantExpression)expression).Value));
            }

            // TODO Move to resx
            throw new NotSupportedException($"Unsupported expression: {expression}");
        }
예제 #2
0
 public void Dispose()
 {
     _current = null;
 }
예제 #3
0
 public MatchingContext()
 {
     _current = this;
 }