C#:打印对象的所有属性 [英] C#: Printing all properties of an object

查看:1069
本文介绍了C#:打印对象的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有内置于.NET可写入所有属性这样一个对象到控制台和方法?可以让使用过程中的反思之一,但我很好奇,如果已经存在......特别是因为你可以在立即窗口做到这一点在Visual Studio中。在那里,您可以将对象名称(而在调试模式下),preSS输入,它是印刷相当prettily其所有的东西。

Is there a method built in to .NET that can write all the properties and such of an object to the console? Could make one using reflection of course, but I'm curious to if this already exists... especially since you can do it in Visual Studio in the Immediate Window. There you can an object name (while in debug mode), press enter, and it is printed fairly prettily with all its stuff.

请问这样的方法存在吗?

Does a method like this exist?

推荐答案

该ObjectDumper类已经知道这样做。我从来没有得到证实,但我一直怀疑,立即窗口使用了。

The ObjectDumper class has been known to do that. I've never confirmed, but I've always suspected that the immediate window uses that.

编辑:我才意识到,那code为ObjectDumper实际上是你的机器上。请访问:

I just realized, that the code for ObjectDumper is actually on your machine. Go to:

C:/ Program Files文件/微软的Visual Studio 9.0 /样品/ 1033 / CSharpSamples.zip

c:/Program Files/Microsoft Visual Studio 9.0/Samples/1033/CSharpSamples.zip

这将解压缩到一个文件夹,名为LinqSamples。在那里,有一个名为ObjectDumper项目。使用它。

This will unzip to a folder called LinqSamples. In there, there's a project called ObjectDumper. Use that.

(这也将使大卫在评论快乐:))

( This will also make David in the comments happy :) )

这篇关于C#:打印对象的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆