Esempio n. 1
0
        protected override Expression VisitMember(MemberExpression node)
        {
            if (!(node.Member is PropertyInfo))
            {
                return(base.VisitMember(node));
            }

            var attr = ((PropertyInfo)node.Member).GetCustomAttribute <Attributes.ExpressionExpandablePropertyAttribute>(inherit: false);

            if (attr == null)
            {
                return(base.VisitMember(node));
            }

            // Visit subtrees first
            node = Expression.MakeMemberAccess(
                expression: Visit(node.Expression),
                member: node.Member);
            Expression customExpanded;

            try {
                // Expand node itself
                customExpanded = attr.CustomExpander.Expand(node, evaluator);
            } catch (Exception e) {
                return(ExceptionClosure.MakeExceptionClosureCall(
                           CustomExpanderException.Create(
                               expander: attr.CustomExpander,
                               expression: node,
                               exception: e),
                           node.Type));
            }
            //Visit result
            return(Visit(customExpanded));
        }
Esempio n. 2
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var attr = node.Method.GetCustomAttribute <Attributes.ExpressionExpandableMethodAttribute>(inherit: false);

            if (attr == null)
            {
                return(base.VisitMethodCall(node));
            }

            // Visit subtrees first
            node = Expression.Call(
                instance: Visit(node.Object),
                method: node.Method,
                arguments: node.Arguments.Select(Visit));
            Expression customExpanded;

            try {
                // Expand node itself
                customExpanded = attr.CustomExpander.Expand(node, evaluator);
            } catch (Exception e) {
                return(ExceptionClosure.MakeExceptionClosureCall(
                           CustomExpanderException.Create(
                               expander: attr.CustomExpander,
                               expression: node,
                               exception: e),
                           node.Type));
            }

            // Visit result
            return(Visit(customExpanded));
        }