Display Property Name and Value

  • Thread starter Thread starter sandeep02
  • Start date Start date
S

sandeep02

Any help on the follwing would be great.

If i have a business object like the folliwng

Object Name : Customer

PropertyName Value
---------------------------
FirstName John
LastName Smith
Address1 123 st. Name
Address2 Apt. 1234
City Bever Hill
State Ca
Zip 12399
Phone 111-111-1111
Job devleoper
Location LA
AGE 27
Skill Dotnet

I am trying to display all these properties in a text box
Is there any easy way to display the propertyname as well as teh value?

I am doing it like this presently

dispTxtBx.Text = "FirstName: " + customer.FirstName;
dispTxtBx.Text = "LastName: " + customer.LastName;
dispTxtBx.Text = "Address1: " + customer.Address1;
dispTxtBx.Text = "Address2: " + customer.Address2;

if the object has too many properties assigned to it very difficult to
display everything.

The above object is just an sample, the object i have is complex than
this.
I wan to create something like the watch window probably.

Any easy way to to display the property name as well as the value?

Any help would be great.
 
public string GetAllProperties(Object obj)
{
StringBuilder sb = new StringBuilder();
foreach (PropertyInfo pi in obj.GetType().GetProperties())
{
sb.AppendFormat("{0}: {1}\n", pi.Name, pi.GetValue(obj, null));
}
return sb.ToString();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top