471,570 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Want function or class that uses reflection to iterate over properties in custom object

I'm writing web applications. I build and extend a lot of custom objects,
and in the course of debugging my apps I invariably find myself writing a
lot of junky code:

Response.Write("Title: " + uwtm.Title + "<br>");
Response.Write("Pubdate: " + uwtm.Pubdate + "<br>");
Response.Write("Byline String: " + uwtm.Byline + "<br>");
Response.Write("Order (converted): " + uwtm.Order + "<br>");
Response.Write("Body:" + uwtm.Body + "<br>");
Response.Write("CategoryId: "+ uwtm.CategoryId + "<br>");

I am lazy and would prefer not to write error-prone code like this. It would
also be nice to be able to discover these properies at runtime and do useful
things. I've learned that you can do this using reflection. Hoping someone
can help me with a few questions:

1) Surely someone has put together a function or class that will take an
object and dump properties and property labels. Can someone offer me code or
a link? Remember that I'm building asp.net apps, not windows forms.

2) Must my custom objects implement IEnumerable for 1) to happen, or is this
baked in?

3) Does anyone know of the best comprehensive newbie introduction to
reflection? I can buy a book if necessary.

Thank you,
Ken Fine

Dec 9 '05 #1
2 1787

Why don't you use the debugger instead of writing debug code. The
debugger will let you see the value of objects, properties, variables
etc at run time. No need to over-complicate things with writing a
reflection class.

ke*****@nospam.nospam wrote:
I'm writing web applications. I build and extend a lot of custom objects,
and in the course of debugging my apps I invariably find myself writing a
lot of junky code:

Response.Write("Title: " + uwtm.Title + "<br>");
Response.Write("Pubdate: " + uwtm.Pubdate + "<br>");
Response.Write("Byline String: " + uwtm.Byline + "<br>");
Response.Write("Order (converted): " + uwtm.Order + "<br>");
Response.Write("Body:" + uwtm.Body + "<br>");
Response.Write("CategoryId: "+ uwtm.CategoryId + "<br>");

I am lazy and would prefer not to write error-prone code like this. It would
also be nice to be able to discover these properies at runtime and do useful
things. I've learned that you can do this using reflection. Hoping someone
can help me with a few questions:

1) Surely someone has put together a function or class that will take an
object and dump properties and property labels. Can someone offer me code or
a link? Remember that I'm building asp.net apps, not windows forms.

2) Must my custom objects implement IEnumerable for 1) to happen, or is this
baked in?

3) Does anyone know of the best comprehensive newbie introduction to
reflection? I can buy a book if necessary.

Thank you,
Ken Fine


Dec 9 '05 #2
This is a great suggestion, thank you.

I've only picked up VS.NET since beta 2 in July, and prior to that I did not
use a "real" IDE with debugging support. So some of my working methods are
still obsolete, as you can see.

Thanks again for the tip.

-KF

"nthomson" <ne**********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...

Why don't you use the debugger instead of writing debug code. The
debugger will let you see the value of objects, properties, variables
etc at run time. No need to over-complicate things with writing a
reflection class.

ke*****@nospam.nospam wrote:
I'm writing web applications. I build and extend a lot of custom objects,
and in the course of debugging my apps I invariably find myself writing a
lot of junky code:

Response.Write("Title: " + uwtm.Title + "<br>");
Response.Write("Pubdate: " + uwtm.Pubdate + "<br>");
Response.Write("Byline String: " + uwtm.Byline + "<br>");
Response.Write("Order (converted): " + uwtm.Order + "<br>");
Response.Write("Body:" + uwtm.Body + "<br>");
Response.Write("CategoryId: "+ uwtm.CategoryId + "<br>");

I am lazy and would prefer not to write error-prone code like this. It
would
also be nice to be able to discover these properies at runtime and do
useful
things. I've learned that you can do this using reflection. Hoping
someone
can help me with a few questions:

1) Surely someone has put together a function or class that will take an
object and dump properties and property labels. Can someone offer me code
or
a link? Remember that I'm building asp.net apps, not windows forms.

2) Must my custom objects implement IEnumerable for 1) to happen, or is
this
baked in?

3) Does anyone know of the best comprehensive newbie introduction to
reflection? I can buy a book if necessary.

Thank you,
Ken Fine

Dec 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Nigel Sampson | last post: by
1 post views Thread by jared lynch | last post: by
3 posts views Thread by Mark Assousa | last post: by
14 posts views Thread by joey.powell | last post: by
4 posts views Thread by =?Utf-8?B?Sm9obiBTaW1wc29u?= | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.