예제 #1
0
        /// <summary>
        /// Returns the value of the <see cref="Expression"/>.
        /// </summary>
        /// <param name="expression"><see cref="Expression"/> to visit.</param>
        /// <returns>Returns the value of the <see cref="Expression"/>.</returns>
        public object VisitResult(SerializableExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            if (_convertedObjects.ContainsKey(expression.HashCode))
            {
                return(_convertedObjects[expression.HashCode]);
            }

            object foundObject;

            SerializableConstantExpression serializableConstantExpression = expression as SerializableConstantExpression;

            if (serializableConstantExpression != null)
            {
                foundObject = GetResultConstantExpression(serializableConstantExpression);
            }
            else
            {
                SerializableMethodCallExpression serializableMethodCallExpression = expression as SerializableMethodCallExpression;
                if (serializableMethodCallExpression != null)
                {
                    foundObject = GetResultMethodCallExpression(serializableMethodCallExpression);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            _convertedObjects[expression.HashCode] = foundObject;
            return(foundObject);
        }
예제 #2
0
        /// <summary>
        /// Visits a <see cref="SerializableConstantExpression"/>.
        /// </summary>
        /// <param name="expression"><see cref="SerializableConstantExpression"/> to visit.</param>
        /// <returns>Returns the converted <see cref="Expression"/>.</returns>
        protected override Expression VisitSerializableConstantExpression(SerializableConstantExpression expression)
        {
            if (expression.Value != null)
            {
                var t = expression.Value.GetType();
#if !NETFX_CORE
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(InterLinqQuery <>))
#else
                if (t.GetTypeInfo().IsGenericType&& t.GetGenericTypeDefinition() == typeof(InterLinqQuery <>))
#endif
                {
                    var qry    = expression.Value as InterLinqQueryBase;
                    var newQry = this.QueryHandler.Get(qry.ElementType, qry.AdditionalObject, qry.QueryName, sessionObject, qry.Parameters);
                    return(Expression.Constant(newQry));
                }
#if !NETFX_CORE
                return(Expression.Constant(expression.Value, expression.Type.GetClrVersion() as Type));
#else
                return(Expression.Constant(expression.Value, ((TypeInfo)expression.Type.GetClrVersion()).AsType()));
#endif
            }
#if !NETFX_CORE
            return(Expression.Constant(null, (Type)expression.Type.GetClrVersion()));
#else
            return(Expression.Constant(null, ((TypeInfo)expression.Type.GetClrVersion()).AsType()));
#endif
        }
예제 #3
0
 /// <summary>
 /// Visits a <see cref="SerializableConstantExpression"/>.
 /// </summary>
 /// <param name="expression"><see cref="SerializableConstantExpression"/> to visit.</param>
 /// <returns>Returns the converted <see cref="Expression"/>.</returns>
 protected override Expression VisitSerializableConstantExpression(SerializableConstantExpression expression)
 {
     if (expression.Value != null)
     {
         return(Expression.Constant(expression.Value, expression.Type.RepresentedType));
     }
     return(Expression.Constant(null, (Type)expression.Type.GetClrVersion()));
 }
예제 #4
0
 /// <summary>
 /// Executes a <see cref="SerializableConstantExpression"/> and returns the result.
 /// </summary>
 /// <param name="expression"><see cref="SerializableConstantExpression"/> to convert.</param>
 /// <returns>Returns the result of a <see cref="SerializableConstantExpression"/>.</returns>
 protected override object GetResultConstantExpression(SerializableConstantExpression expression)
 {
     if (expression.Value == null)
     {
         return(null);
     }
     if (expression.Value is InterLinqQueryBase)
     {
         Type type = ((InterLinqQueryBase)expression.Value).ElementType;
         return(QueryHandler.Get(type));
     }
     return(expression.Value);
 }
예제 #5
0
        /// <summary>
        /// Executes a <see cref="SerializableConstantExpression"/> and returns the result.
        /// </summary>
        /// <param name="expression"><see cref="SerializableConstantExpression"/> to convert.</param>
        /// <returns>Returns the result of a <see cref="SerializableConstantExpression"/>.</returns>
        protected override object GetResultConstantExpression(SerializableConstantExpression expression, object sessionObject)
        {
            if (expression.Value == null)
            {
                return(null);
            }
            if (expression.Value is InterLinqQueryBase)
            {
                InterLinqQueryBase baseQuery = (InterLinqQueryBase)expression.Value;

                Type type = ((InterLinqQueryBase)expression.Value).ElementType;

                return(QueryHandler.Get(type, baseQuery.AdditionalObject, baseQuery.QueryName, sessionObject,
                                        (!string.IsNullOrEmpty(baseQuery.QueryName) && baseQuery.QueryParameters != null &&
                                         baseQuery.QueryParameters.Count != 0)
                        ? baseQuery.QueryParameters.Select(s => VisitResult(s, sessionObject)).ToArray()
                        : baseQuery.Parameters));
                //return QueryHandler.Get(type, baseQuery.AdditionalObject, baseQuery.QueryName, sessionObject, (!string.IsNullOrEmpty(baseQuery.QueryName) && baseQuery.QueryParameters != null && baseQuery.QueryParameters.Count != 0) ? baseQuery.QueryParameters.Select(s => VisitResult(s, sessionObject)).ToArray() : null);
            }
            return(expression.Value);
        }
예제 #6
0
 /// <summary>
 /// Executes a <see cref="SerializableConstantExpression"/> and returns the result.
 /// </summary>
 /// <param name="expression"><see cref="SerializableConstantExpression"/> to convert.</param>
 /// <returns>Returns the result of a <see cref="SerializableConstantExpression"/>.</returns>
 protected abstract object GetResultConstantExpression(SerializableConstantExpression expression);
예제 #7
0
 /// <summary>
 /// Visits a <see cref="SerializableConstantExpression"/>.
 /// </summary>
 /// <param name="expression"><see cref="SerializableConstantExpression"/> to visit.</param>
 /// <returns>Returns the converted <see cref="Expression"/>.</returns>
 protected abstract Expression VisitSerializableConstantExpression(SerializableConstantExpression expression);
 private Expression VisitConstant(SerializableConstantExpression c)
 {
     return(Expression.Constant(c.Value, c.Type));
 }