コード例 #1
0
        internal static IArgumentValidator GetArgumentValidatorForArgument(MethodCallExpression expression)
        {
            var argumentsForConstructor = expression.Arguments.Skip(1).Select(x => ExpressionManager.GetValueProducedByExpression(x)).ToArray();
            var validatorType           = GetValidatorType(expression);

            AssertValidatorTypeImplementsArgumentValidatorInterface(validatorType);

            EnsureThatValidatorConstructorMatchesSignatureOfExtensionMethod(expression.Method, validatorType);

            var validator = (IArgumentValidator)Activator.CreateInstance(validatorType, argumentsForConstructor);


            return(validator);
        }
コード例 #2
0
ファイル: A.cs プロジェクト: BGCX067/fakeiteasy-svn-to-git
        public static T Fake <T>(Expression <Func <T> > constructorCall) where T : class
        {
            Guard.IsNotNull(constructorCall, "constructorCall");

            if (constructorCall.Body.NodeType != ExpressionType.New)
            {
                throw new ArgumentException(ExceptionMessages.NonConstructorExpressionMessage);
            }

            var constructorArguments =
                (from argument in ((NewExpression)constructorCall.Body).Arguments
                 select ExpressionManager.GetValueProducedByExpression(argument)).ToArray();

            return((T) new FakeObject(typeof(T), constructorArguments).Object);
        }