Property List

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

I want to write a routine which will list all of the propetries and all
property names for a particular object, say a DataColumn. I there a way
for me to do this without manually looking up each property name and the
property value?


Thanks in advance for your assistance!!!!!!!!!!!
 
Hi Jim,

You might take a look at reflection.
Type.GetProperties method is what you need.
 
I suggest you take a look at the PropertyGrid control:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/usingpropgrid.asp
If you have used Microsoft® Visual Basic® or Microsoft Visual Studio .NET
then you have used a property browser to browse, view, and edit the
properties of one or more objects. The .NET Framework PropertyGrid control
is core to the property browser that is in Visual Studio .NET. The
PropertyGrid control displays properties for any object or type, and it
retrieves the item's properties, primarily using reflection. (Reflection is
a technology that provides type information at run time.)

Otherwise, if you want to do it all manually, you can use refelection:
object o;

foreach(System.Reflection.PropertyInfo pi in o.GetType().GetProperties())
{
MessageBox.Show(pi.Name);
}
object o;

foreach(System.Reflection.PropertyInfo pi in o.GetType().GetProperties())
{
MessageBox.Show(pi.Name);
}
 
Back
Top