Exemple #1
0
        /// <summary>
        ///     Gets the current value of the parameter given (optional) compiled query arguments.
        /// </summary>
        internal object EvaluateParameter(object[] arguments)
        {
            if (_cachedDelegate == null)
            {
                if (_funcletizedExpression.NodeType
                    == ExpressionType.Constant)
                {
                    return(((ConstantExpression)_funcletizedExpression).Value);
                }
                ConstantExpression ce;
                if (TryEvaluatePath(_funcletizedExpression, out ce))
                {
                    return(ce.Value);
                }
            }

            try
            {
                if (_cachedDelegate == null)
                {
                    // Get the Func<> type for the property evaluator
                    var delegateType = TypeSystem.GetDelegateType(_compiledQueryParameters.Select(p => p.Type), _type);

                    // Now compile delegate for the funcletized expression
                    _cachedDelegate = Lambda(delegateType, _funcletizedExpression, _compiledQueryParameters).Compile();
                }
                return(_cachedDelegate.DynamicInvoke(arguments));
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
Exemple #2
0
 internal object EvaluateParameter(object[] arguments)
 {
     if ((object)this._cachedDelegate == null)
     {
         if (this._funcletizedExpression.NodeType == ExpressionType.Constant)
         {
             return(((ConstantExpression)this._funcletizedExpression).Value);
         }
         ConstantExpression constantExpression;
         if (QueryParameterExpression.TryEvaluatePath(this._funcletizedExpression, out constantExpression))
         {
             return(constantExpression.Value);
         }
     }
     try
     {
         if ((object)this._cachedDelegate == null)
         {
             this._cachedDelegate = Expression.Lambda(TypeSystem.GetDelegateType(this._compiledQueryParameters.Select <ParameterExpression, Type>((Func <ParameterExpression, Type>)(p => p.Type)), this._type), this._funcletizedExpression, this._compiledQueryParameters).Compile();
         }
         return(this._cachedDelegate.DynamicInvoke(arguments));
     }
     catch (TargetInvocationException ex)
     {
         throw ex.InnerException;
     }
 }