當前位置: 首頁>>代碼示例>>C#>>正文


C# Expression.BuildString方法代碼示例

本文整理匯總了C#中System.Linq.Expressions.Expression.BuildString方法的典型用法代碼示例。如果您正苦於以下問題:C# Expression.BuildString方法的具體用法?C# Expression.BuildString怎麽用?C# Expression.BuildString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Linq.Expressions.Expression的用法示例。


在下文中一共展示了Expression.BuildString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FindAccessorLambda

    /// <summary>
    /// Constructs a <see cref="LambdaExpression"/> that is able to extract a specific simple <paramref name="searchedExpression"/> from a 
    /// complex <paramref name="fullExpression"/>.
    /// </summary>
    /// <param name="searchedExpression">The expression an accessor to which should be created.</param>
    /// <param name="fullExpression">The full expression containing the <paramref name="searchedExpression"/>.</param>
    /// <param name="inputParameter">The input parameter to be used by the resulting lambda. Its type must match the type of <paramref name="fullExpression"/>.</param>
    /// <remarks>The <see cref="AccessorFindingExpressionVisitor"/> compares the <paramref name="searchedExpression"/> via reference equality,
    /// which means that exactly the same expression reference must be contained by <paramref name="fullExpression"/> for the visitor to return the
    /// expected result. In addition, the visitor can only provide accessors for expressions nested in <see cref="NewExpression"/> or 
    /// <see cref="MemberInitExpression"/>.</remarks>
    /// <returns>A <see cref="LambdaExpression"/> acting as an accessor for the <paramref name="searchedExpression"/> when an input matching 
    /// <paramref name="fullExpression"/> is given.
    /// </returns>
    public static LambdaExpression FindAccessorLambda (Expression searchedExpression, Expression fullExpression, ParameterExpression inputParameter)
    {
      ArgumentUtility.CheckNotNull ("searchedExpression", searchedExpression);
      ArgumentUtility.CheckNotNull ("fullExpression", fullExpression);
      ArgumentUtility.CheckNotNull ("inputParameter", inputParameter);

      if (inputParameter.Type != fullExpression.Type)
      {
        throw new ArgumentException (
            string.Format ("The inputParameter's type '{0}' must match the fullExpression's type '{1}'.", inputParameter.Type, fullExpression.Type),
            "inputParameter");
      }

      var visitor = new AccessorFindingExpressionVisitor (searchedExpression, inputParameter);
      visitor.Visit (fullExpression);

      if (visitor.AccessorPath != null)
        return visitor.AccessorPath;
      else
      {
        var message = string.Format (
            "The given expression '{0}' does not contain the searched expression '{1}' in a nested NewExpression with member assignments or a "
                + "MemberBindingExpression.",
            fullExpression.BuildString(),
            searchedExpression.BuildString());
        throw new ArgumentException (message, "fullExpression");
      }
    }
開發者ID:natemcmaster,項目名稱:Relinq,代碼行數:42,代碼來源:AccessorFindingExpressionVisitor.cs

示例2: CheckAreEqualTrees

    public static void CheckAreEqualTrees (Expression expectedTree, Expression actualTree)
    {
      ArgumentUtility.CheckNotNull ("expectedTree", expectedTree);
      ArgumentUtility.CheckNotNull ("actualTree", actualTree);

      var comparer = new ExpressionTreeComparer (
          expectedTree.BuildString(),
          actualTree.BuildString());
      comparer.CheckAreEqualNodes (expectedTree, actualTree);
    }
開發者ID:natemcmaster,項目名稱:Relinq,代碼行數:10,代碼來源:ExpressionTreeComparer.cs

示例3: ParseTree

    /// <summary>
    /// Parses the given <paramref name="expressionTree"/> into a chain of <see cref="IExpressionNode"/> instances, using 
    /// <see cref="MethodInfoBasedNodeTypeRegistry"/> to convert expressions to nodes.
    /// </summary>
    /// <param name="expressionTree">The expression tree to parse.</param>
    /// <returns>A chain of <see cref="IExpressionNode"/> instances representing the <paramref name="expressionTree"/>.</returns>
    public IExpressionNode ParseTree (Expression expressionTree)
    {
      ArgumentUtility.CheckNotNull ("expressionTree", expressionTree);

      if (expressionTree.Type == typeof (void))
      {
        throw new NotSupportedException (
            string.Format ("Expressions of type void ('{0}') are not supported.", expressionTree.BuildString()));
      }

      var processedExpressionTree = _processor.Process (expressionTree);
      return ParseNode (processedExpressionTree, null);
    }
開發者ID:natemcmaster,項目名稱:Relinq,代碼行數:19,代碼來源:ExpressionTreeParser.cs


注:本文中的System.Linq.Expressions.Expression.BuildString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。