Simplest way I believe is:
Type t = f.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo pi in props) {
Console.WriteLine("Property {0}, value {1}", pi.Name, pi.GetValue(f, null));
}
Here is sample of produced output for a form (f = new Form();)
....
Property BackgroundImage, value
Property BackgroundImageLayout, value Tile
Property Bottom, value 322
Property Bounds, value {X=22,Y=22,Width=300,Height=300}
Property CanFocus, value False
Property CanSelect, value False
Property Capture, value False
Property CausesValidation, value True
Property ClientRectangle, value {X=0,Y=0,Width=292,Height=273}
Property CompanyName, value Microsoft Corporation
Property ContainsFocus, value False
Property ContextMenu, value
Property ContextMenuStrip, value
Property Controls, value System.Windows.Forms.Form+ControlCollection
Property Created, value False
Property Cursor, value [Cursor: Default]
Property DataBindings, value System.Windows.Forms.ControlBindingsCollection
....
You'll might need to tweak BindingFlags and indexes to get to arrays and
special cases, however this should do the desired in most cases
Have fun
Alex
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:Om**************@TK2MSFTNGP06.phx.gbl...
Hi
Is there an easy or a built-in way to collect all properties of an object
into a string variable for debugging purpose? I am looking for something
similar to this;
"Property1: Property1value
Property2: Property2value
Property3: Property3value
....
Propertyn: Propertynvalue"
Thanks
Regards