问题
Given (new [] {"a", "b"}).Dump()
, LinqPad provides some very useful print results.
It seems that this extension method is a short hand for Console.WriteLine
.
Question> how to implement this dump for myself?
回答1:
This thread might be of use to you. Is there a library that provides a formatted Dump( ) function like LinqPad?
回答2:
With a lot of hard work.
Dump
is not a shortcut for Console.WriteLine
; it's an extremely complicated recursive method which turns arbitrary object graphs into HTML, with special support for collections, DataTable
s, Image
s, and a couple of other types.
It also has special output code to format collections of complex objects into tables, and to prevent recursive expansion.
回答3:
You can grab the Object Dumper
class that is included in the Visual C# 2008 Samples. It won't be in the pretty HTML format used by LINQPad and the other types of output it supports, but the purpose is similar.
来源:https://stackoverflow.com/questions/6207386/how-to-implement-dump-as-the-one-provided-by-linqpad