I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString()
on all of an object's properties and format it nicely for display.
我记得很久以前就有一些方法可能是Reflection命名空间,它会在所有对象的属性上递归运行ToString()并很好地为显示格式化。
Yes, I know everything I could want will be accessible through the debugger, but I'm wondering if anyone knows that command?
是的,我知道我想要的一切都可以通过调试器访问,但我想知道是否有人知道这个命令?
5 个解决方案
#1
8
I think what you're looking for is/was called ObjectDumper. It uses reflection to iterate through and output all of the different properties for an object. I first heard about it while learning LINQ, and most of the examples in the Linq in Action book use it.
我认为你正在寻找的是/被称为ObjectDumper。它使用反射来迭代并输出对象的所有不同属性。我在学习LINQ时第一次听说过它,而Linq in Action一书中的大多数例子都使用它。
It appears that Microsoft didn't include it in the final version of Linq though, but the code is still out in the wild. I did a quick google search for it and here's a link to it:
看起来微软并没有将它包含在Linq的最终版本中,但代码仍处于疯狂状态。我做了一个快速谷歌搜索它,这是一个链接:
ObjectDumper源代码
#2
4
Example code to dump an object and its properties can be found here:
可以在此处找到转储对象及其属性的示例代码:
#3
0
I could certainly see the use in such a thing, but in .Net won't you mostly just get a list of type names (String, Array, etc)? Most of the built-ins don't have "useful" ToString() overloads pre-written, do they?
我当然可以在这样的事情中看到它的使用,但在.Net中你不会只获得一个类型名称列表(String,Array等)吗?大多数内置函数没有预先编写的“有用”ToString()重载,是吗?
#4
0
Here is a link with code dumper and a demo project that shows you how to use it. Download it here.
这是一个链接代码转储器和一个演示项目,向您展示如何使用它。在这里下载。
#5
0
You can write it by yourself. For example, serialize it into json using Newtonsoft's JSON.net library and write that json to console. Here is an example:
你可以自己写。例如,使用Newtonsoft的JSON.net库将其序列化为json,并将该json写入控制台。这是一个例子:
using Newtonsoft.Json;
static class Pretty
{
public static void Print<T> (T x)
{
string json = JsonConvert.SerializeObject(x, Formatting.Indented);
Console.WriteLine(json);
}
}
Usage:
Pretty.Print(whatever);
#1
8
I think what you're looking for is/was called ObjectDumper. It uses reflection to iterate through and output all of the different properties for an object. I first heard about it while learning LINQ, and most of the examples in the Linq in Action book use it.
我认为你正在寻找的是/被称为ObjectDumper。它使用反射来迭代并输出对象的所有不同属性。我在学习LINQ时第一次听说过它,而Linq in Action一书中的大多数例子都使用它。
It appears that Microsoft didn't include it in the final version of Linq though, but the code is still out in the wild. I did a quick google search for it and here's a link to it:
看起来微软并没有将它包含在Linq的最终版本中,但代码仍处于疯狂状态。我做了一个快速谷歌搜索它,这是一个链接:
ObjectDumper源代码
#2
4
Example code to dump an object and its properties can be found here:
可以在此处找到转储对象及其属性的示例代码:
#3
0
I could certainly see the use in such a thing, but in .Net won't you mostly just get a list of type names (String, Array, etc)? Most of the built-ins don't have "useful" ToString() overloads pre-written, do they?
我当然可以在这样的事情中看到它的使用,但在.Net中你不会只获得一个类型名称列表(String,Array等)吗?大多数内置函数没有预先编写的“有用”ToString()重载,是吗?
#4
0
Here is a link with code dumper and a demo project that shows you how to use it. Download it here.
这是一个链接代码转储器和一个演示项目,向您展示如何使用它。在这里下载。
#5
0
You can write it by yourself. For example, serialize it into json using Newtonsoft's JSON.net library and write that json to console. Here is an example:
你可以自己写。例如,使用Newtonsoft的JSON.net库将其序列化为json,并将该json写入控制台。这是一个例子:
using Newtonsoft.Json;
static class Pretty
{
public static void Print<T> (T x)
{
string json = JsonConvert.SerializeObject(x, Formatting.Indented);
Console.WriteLine(json);
}
}
Usage:
Pretty.Print(whatever);