Example #1
0
        /// <summary>
        /// Replaces the given parameter with a back-reference to the <see cref="IQuerySource"/> corresponding to <paramref name="referencedNode"/>.
        /// </summary>
        /// <param name="referencedNode">The referenced node.</param>
        /// <param name="parameterToReplace">The parameter to replace with a <see cref="QuerySourceReferenceExpression"/>.</param>
        /// <param name="expression">The expression in which to replace the parameter.</param>
        /// <param name="context">The clause generation context.</param>
        /// <returns><paramref name="expression"/>, with <paramref name="parameterToReplace"/> replaced with a <see cref="QuerySourceReferenceExpression"/>
        /// pointing to the clause corresponding to <paramref name="referencedNode"/>.</returns>
        public static Expression ReplaceParameterWithReference(
            IQuerySourceExpressionNode referencedNode,
            ParameterExpression parameterToReplace,
            Expression expression,
            ClauseGenerationContext context)
        {
            var clause = GetQuerySourceForNode(referencedNode, context);
            var referenceExpression = new QuerySourceReferenceExpression(clause);

            return(ReplacingExpressionTreeVisitor.Replace(parameterToReplace, referenceExpression, expression));
        }
Example #2
0
 /// <summary>
 /// Gets the <see cref="IQuerySource"/> corresponding to the given <paramref name="node"/>, throwing an <see cref="InvalidOperationException"/>
 /// if no such clause has been registered in the given <paramref name="context"/>.
 /// </summary>
 /// <param name="node">The node for which the <see cref="IQuerySource"/> should be returned.</param>
 /// <param name="context">The clause generation context.</param>
 /// <returns>The <see cref="IQuerySource"/> corresponding to <paramref name="node"/>.</returns>
 public static IQuerySource GetQuerySourceForNode(IQuerySourceExpressionNode node, ClauseGenerationContext context)
 {
     try
     {
         return((IQuerySource)context.GetContextInfo(node));
     }
     catch (KeyNotFoundException ex)
     {
         var message = string.Format(
             "Cannot retrieve an IQuerySource for the given {0}. Be sure to call Apply before calling methods that require IQuerySources, and pass in "
             + "the same QuerySourceClauseMapping to both.",
             node.GetType().Name);
         throw new InvalidOperationException(message, ex);
     }
 }
 /// <summary>
 /// Gets the <see cref="IQuerySource"/> corresponding to the given <paramref name="node"/>, throwing an <see cref="InvalidOperationException"/>
 /// if no such clause has been registered in the given <paramref name="context"/>.
 /// </summary>
 /// <param name="node">The node for which the <see cref="IQuerySource"/> should be returned.</param>
 /// <param name="context">The clause generation context.</param>
 /// <returns>The <see cref="IQuerySource"/> corresponding to <paramref name="node"/>.</returns>
 public static IQuerySource GetQuerySourceForNode (IQuerySourceExpressionNode node, ClauseGenerationContext context)
 {
   try
   {
     return (IQuerySource) context.GetContextInfo (node);
   }
   catch (KeyNotFoundException ex)
   {
     var message = string.Format (
         "Cannot retrieve an IQuerySource for the given {0}. Be sure to call Apply before calling methods that require IQuerySources, and pass in "
         + "the same QuerySourceClauseMapping to both.",
         node.GetType().Name);
     throw new InvalidOperationException (message, ex);
   }
 }
Example #4
0
        /// <summary>
        /// Replaces the given parameter with a back-reference to the <see cref="IQuerySource"/> corresponding to <paramref name="referencedNode"/>.
        /// </summary>
        /// <param name="referencedNode">The referenced node.</param>
        /// <param name="parameterToReplace">The parameter to replace with a <see cref="QuerySourceReferenceExpression"/>.</param>
        /// <param name="expression">The expression in which to replace the parameter.</param>
        /// <param name="context">The clause generation context.</param>
        /// <returns><paramref name="expression"/>, with <paramref name="parameterToReplace"/> replaced with a <see cref="QuerySourceReferenceExpression"/>
        /// pointing to the clause corresponding to <paramref name="referencedNode"/>.</returns>
        public static Expression ReplaceParameterWithReference(
            IQuerySourceExpressionNode referencedNode,
            ParameterExpression parameterToReplace,
            Expression expression,
            ClauseGenerationContext context)
        {
            ArgumentUtility.CheckNotNull("referencedNode", referencedNode);
            ArgumentUtility.CheckNotNull("parameterToReplace", parameterToReplace);
            ArgumentUtility.CheckNotNull("expression", expression);
            ArgumentUtility.CheckNotNull("context", context);

            var clause = GetQuerySourceForNode(referencedNode, context);
            var referenceExpression = new QuerySourceReferenceExpression(clause);

            return(ReplacingExpressionTreeVisitor.Replace(parameterToReplace, referenceExpression, expression));
        }
    /// <summary>
    /// Replaces the given parameter with a back-reference to the <see cref="IQuerySource"/> corresponding to <paramref name="referencedNode"/>.
    /// </summary>
    /// <param name="referencedNode">The referenced node.</param>
    /// <param name="parameterToReplace">The parameter to replace with a <see cref="QuerySourceReferenceExpression"/>.</param>
    /// <param name="expression">The expression in which to replace the parameter.</param>
    /// <param name="context">The clause generation context.</param>
    /// <returns><paramref name="expression"/>, with <paramref name="parameterToReplace"/> replaced with a <see cref="QuerySourceReferenceExpression"/>
    /// pointing to the clause corresponding to <paramref name="referencedNode"/>.</returns>
    public static Expression ReplaceParameterWithReference (
        IQuerySourceExpressionNode referencedNode, 
        ParameterExpression parameterToReplace, 
        Expression expression, 
        ClauseGenerationContext context)
    {
      ArgumentUtility.CheckNotNull ("referencedNode", referencedNode);
      ArgumentUtility.CheckNotNull ("parameterToReplace", parameterToReplace);
      ArgumentUtility.CheckNotNull ("expression", expression);
      ArgumentUtility.CheckNotNull ("context", context);

      var clause = GetQuerySourceForNode (referencedNode, context);
      var referenceExpression = new QuerySourceReferenceExpression (clause);

      return ReplacingExpressionTreeVisitor.Replace (parameterToReplace, referenceExpression, expression);
    }
 public void SetUp()
 {
     _context     = new ClauseGenerationContext(new MethodInfoBasedNodeTypeRegistry());
     _node        = new MainSourceExpressionNode("x", Expression.Constant(new int[0]));
     _querySource = new MainFromClause("x", typeof(int), Expression.Constant(new int[0]));
 }
 public void SetUp ()
 {
   _context = new ClauseGenerationContext (new MethodInfoBasedNodeTypeRegistry());
   _node = new MainSourceExpressionNode ("x", Expression.Constant (new int[0]));
   _querySource = new MainFromClause ("x", typeof (int), Expression.Constant (new int[0]));
 }