Source/NFX/MiscUtils.cs
/// <summary>
/// Converts expression tree to simple textual form for debugging
/// </summary>
Converts expression tree to simple textual form for debugging
Converts expression tree to simple textual form for debugging
public static string ToDebugView(this Expression expr, int indent = 0)
    {
      const int TS = 2;
      var pad = "".PadLeft(TS*indent,' ');
      if (expr==null) return "";
      if (expr is BlockExpression)
      {
        var block = (BlockExpression)expr;
        var sb = new StringBuilder();
        sb.Append(pad);  sb.AppendLine("{0}{{".Args(expr.GetType().Name));
        sb.Append(pad);  sb.AppendLine("//variables");
        foreach( var v in block.Variables)
        {
           sb.Append(pad);
           sb.AppendLine("var {0}  {1};" .Args(v.Type.FullName, v.Name));
        }
        sb.Append(pad); sb.AppendLine("//sub expressions");
        foreach( var se in block.Expressions)
        {
           sb.Append(pad);
           sb.AppendLine( se.ToDebugView(indent+1) );
        }
        sb.Append(pad); sb.AppendLine("}");
        return sb.ToString();
      }
      return pad + expr.ToString();
    }
public static string ToDebugView ( this Expression expr , int indent = 0 ) { const int TS = 2 ; var pad = " " . PadLeft ( TS * indent , ' ' ) ; if ( expr == null ) return " " ; if ( expr is BlockExpression ) { var block = ( BlockExpression ) expr ; var sb = new StringBuilder ( ) ; sb . Append ( pad ) ; sb . AppendLine ( " " . Args ( expr . GetType ( ) . Name ) ) ; sb . Append ( pad ) ; sb . AppendLine ( " " ) ; foreach ( var v in block . Variables ) { sb . Append ( pad ) ; sb . AppendLine ( " " . Args ( v . Type . FullName , v . Name ) ) ; } sb . Append ( pad ) ; sb . AppendLine ( " " ) ; foreach ( var se in block . Expressions ) { sb . Append ( pad ) ; sb . AppendLine ( se . ToDebugView ( indent + 1 ) ) ; } sb . Append ( pad ) ; sb . AppendLine ( " " ) ; return sb . ToString ( ) ; } return pad + expr . ToString ( ) ; }
Converts expression tree to simple textual form for debugging
Converts expression tree to simple textual form for debugging
Expression
this
indent
int