/// <summary> /// Evaluates the expression using the given expression policy. /// </summary> /// <typeparam name="T">The expected result type.</typeparam> /// <param name="policy">The expression policy.</param> /// <param name="expression">The expression.</param> /// <returns>The result of evaluating the expression with the given policy.</returns> public static T Evaluate <T>(this IExpressionEvaluationPolicy policy, Expression expression) { if (policy == null) { throw new ArgumentNullException(nameof(policy)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var delegateCache = policy.DelegateCache; if (delegateCache == null) { throw new ArgumentException("Expected non-null compiled delegate cache.", nameof(policy)); } var constantHoister = policy.ConstantHoister; if (constantHoister == null) { throw new ArgumentException("Expected non-null constant hoister.", nameof(policy)); } var lambda = Expression.Lambda <Func <T> >(expression); return(lambda.Compile(delegateCache, policy.OutlineCompilation, constantHoister)()); }
/// <summary> /// Creates a new quoted representation of a subscribable sequence. /// </summary> /// <param name="value">Subscribable sequence to create a quote for.</param> /// <param name="expression">Expression representing the subscribable sequence.</param> /// <param name="policy">Policy used to evaluate the expression.</param> public QuotedSubscribable(ISubscribable <T> value, Expression expression, IExpressionEvaluationPolicy policy) : base(value, expression, policy) { // // WARNING: This constructor gets called during quote instantiation. // }
/// <summary> /// Creates a new quoted representation of a subscribable sequence. /// </summary> /// <param name="expression">Expression representing the subscribable sequence.</param> /// <param name="policy">Policy used to evaluate the expression.</param> public QuotedSubscribable(Expression expression, IExpressionEvaluationPolicy policy) : base(expression, policy) { // // WARNING: This constructor gets called during deserialization of persisted subscriptions. // }
/// <summary> /// Creates a new quoted value using the specified expression tree. /// </summary> /// <param name="value">Value of the quote.</param> /// <param name="expression">Expression representing the quoted value.</param> /// <param name="policy">Policy used to evaluate the expression.</param> public Quoted(T value, Expression expression, IExpressionEvaluationPolicy policy) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } if (!typeof(T).IsAssignableFrom(expression.Type)) { throw new ArgumentException("The specified expression does not have a type compatible with the specified value.", nameof(expression)); } Value = value; _expression = policy.InMemoryCache.Create(expression); }
/// <summary> /// Creates a new quoted value using the specified expression tree. /// </summary> /// <param name="expression">Expression representing the quoted value.</param> /// <param name="policy">Policy used to evaluate the expression.</param> public Quoted(Expression expression, IExpressionEvaluationPolicy policy) : this(policy.Evaluate <T>(expression), expression, policy) { }
public QuoteConverter(IExpressionEvaluationPolicy expressionPolicy) { _expressionPolicy = expressionPolicy; }