コード例 #1
0
        protected override Expression VisitNew(NewExpression node)
        {
            _structureService.VerifyType(node.Type, TypeVerifiers);
            _structureService.VerifyMember(
                node.Constructor,
                MemberVerifiers,
                MemberVerificationAspect.MemberType,
                MemberVerificationAspect.ConstructorAccessLevel);

            MemberInfo memberInfo = _structureService.TranslateMember(node.Constructor);

            return(Expression.New((ConstructorInfo)memberInfo, node.Arguments.Select(Visit)));
        }
コード例 #2
0
        public void VisitCorrectlyTransformsMethodCallExpression()
        {
            IStructureService service = Substitute.For <IStructureService>();

            service.TranslateType(typeof(ClassA)).Returns(typeof(ClassB));
            service.TranslateMember(ClassAVoidMethod).Returns(ClassBVoidMethod);
            TypeVisitor visitor = new TypeVisitor(service)
            {
                TypeVerifiers   = new ITypeVerifier[0],
                MemberVerifiers = new IMemberVerifier[0]
            };

            Expression input    = Expression.Call(Expression.Parameter(typeof(ClassA)), ClassAVoidMethod);
            Expression expected = Expression.Call(Expression.Parameter(typeof(ClassB)), ClassBVoidMethod);

            Expression actual = visitor.Visit(input);

            AssertAreEqualExpressions(expected, actual);
        }