【问题标题】:Canonical Console.WriteLine in LinqPadLinqPad 中的规范 Console.WriteLine
【发布时间】:2012-10-04 11:24:58
【问题描述】:

Linqpad 的增强版 Console.WriteLine 很棒。但是,我怎样才能做一个标准的 Console.WriteLine 对象呢?

【问题讨论】:

  • 如果这个尊重Consolecolors

标签: linqpad


【解决方案1】:

Debug.WriteLine 也可以解决问题。

【讨论】:

  • 如果这个尊重Consolecolors
【解决方案2】:

嗯,现在很明显 - 放入显式 ToString

Console.WriteLine(x.ToString());

【讨论】:

    【解决方案3】:

    您还可以将这些方法添加到“我的查询”窗格中的“我的扩展”文件中。这样您就可以使用 .DumpToString 而不是 .Dump。也许它们应该重命名为 DumpDebug ...

    // Write custom extension methods here. They will be available to all queries.
    public static void DumpToString<T>(this IEnumerable<T> list)
    {
        list.ToList().ForEach(x => Debug.WriteLine(x));
    }
    
    public static void DumpToString(this object o)
    {
        Debug.WriteLine(o);
    }
    
    public static void DumpToString(this string o)
    {
        Debug.WriteLine(o);
    }
    

    【讨论】:

      【解决方案4】:

      你也可以这样做

      x.Dump();
      

      它将使用 LinqPad API 来漂亮地格式化输出。

      【讨论】:

      • 这正是 OP 在这种情况下想要避免的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多