Exemple #1
0
        /// <summary>
        /// 访问表示方法调用的节点
        /// </summary>
        /// <param name="node">方法调用节点</param>
        /// <returns></returns>
        public virtual Expression VisitMethodCall(MethodCallExpression node)
        {
            Type   type       = node.Method.ReflectedType != null ? node.Method.ReflectedType : node.Method.DeclaringType;
            string methodName = string.Empty;

            if (type == typeof(SqlMethod) || type == typeof(Guid))
            {
                methodName = "VisitSQL";
            }
            else if (type == typeof(string) || node.Method.Name == "ToString")
            {
                methodName = "VisitSTR";
            }
            else if (type == typeof(Enumerable) || typeof(IEnumerable).IsAssignableFrom(type))
            {
                methodName = "VisitENM";
            }

            if (_typeRuntime == null)
            {
                _typeRuntime = new VistorTypeRuntimeInfo(this.GetType());
            }
            MemberInvokerBase invoker = _typeRuntime.GetInvoker(methodName + node.Method.Name);

            if (invoker != null)
            {
                object exp = invoker.Invoke(this, new object[] { node });
                return(exp as Expression);
            }

            throw new XFrameworkException("{0}.{1} is not supported.", node.Method.DeclaringType, node.Method.Name);
        }
Exemple #2
0
        /// <summary>
        /// 访问表示字段或者属性的属性的节点 a.Name.Length
        /// </summary>
        public virtual Expression VisitMemberMember(MemberExpression node)
        {
            Type   type       = node.Expression.Type;
            string methodName = string.Empty;

            if (type == typeof(string))
            {
                methodName = "VisitSTR";
            }

            if (_typeRuntime == null)
            {
                _typeRuntime = new VistorTypeRuntimeInfo(this.GetType());
            }
            MemberInvokerBase invoker = _typeRuntime.GetInvoker(methodName + node.Member.Name);

            if (invoker != null)
            {
                object exp = invoker.Invoke(this, new object[] { node });
                return(exp as Expression);
            }

            throw new XFrameworkException("{0}.{1} is not supported.", node.Member.DeclaringType, node.Member.Name);
        }