如何在 Visual Studio 中使用 LINQPad Dump() 扩展方法?
LINQPad 令人惊叹,特别有用的是 Dump()
扩展方法,它可以将几乎任何类型(匿名与否)的对象和结构呈现到控制台。
最初,当我迁移到 Visual Studio 2010 时,我尝试使用委托创建自己的 Dump
方法来获取要呈现的匿名类型等的值。虽然它变得非常复杂,但也很有趣首先是教育性的,我需要一个坚实的实施。在查看 .NET Reflector 中的 LINQPad 代码后,我更加确信我不是将得到正确的实施。
是否有免费的库可以提供 Dump
功能?
LINQPad is amazing, and particularly useful is the Dump()
extension methods which renders objects and structs of almost any type, anonymous or not, to the console.
Initially, when I moved to Visual Studio 2010, I tried to make my own Dump
method using a delegate to get the values to render for anonymous types, etc. It's getting pretty complicated though and while it was fun and educational at first, I need a solid implementation. Having checked out the LINQPad code in .NET Reflector I am even more assured that I'm not going to get the implementation right.
Is there a free library I can include to provide the Dump
functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我为 Object 编写了一个扩展方法,该方法使用带有漂亮格式选项的 Json.Net 序列化器。当采用这样的格式时,JSON 很容易阅读。您错过了类型信息,但我不知道您是否需要它,特别是考虑到这是多么容易。还没有让我失望。我使用 Json.Net 而不是 MS',因为它能够处理复杂图中的循环引用,而 MS' 不能,或者在我想到它时没有。
I wrote an extension method to Object that uses the Json.Net serializer with the pretty format option. JSON is easy enough to read when formatted like that. You miss type info, but I don't know that you need that, especially considering how easy this is. Hasn't failed me yet. I use Json.Net and not MS' because it has the capability of handling circular references in complex graphs, where MS' cannot, or didn't at the time I thought of it.
看这里(您的路径可能会有所不同):
Look here (your path may vary):
diceguyd30的答案 源自 讨论(尤其是 Pat Kujawa 和 anunay 的评论)并描述了如何从 C# 和 VB.NET 调用 LINQPad 转储实现:
diceguyd30's answer is sourced from a discussion (especially Pat Kujawa's & anunay's comments) and describes how to call the LINQPad dump implementation from both C# and VB.NET:
还有名为 ObjectDumper 的类库作为 NuGet 包提供。
There's also a class library named ObjectDumper available as a NuGet package.