reflection - discover control's properties.

  • Thread starter Thread starter roy
  • Start date Start date
R

roy

Hi.
I would like to be able to iterate recursively through a
web page, and for every control on the page, chech if it
has "CssClass" property and to be able to change it.
How can this be done?
Thanks
Roy
 
Hi

You can use classes TypeDescriptor and ProperyDescriptor.

To obtain values of every property of a class use static function
TypeDescriptor.GetProperties.
This function returns PropertyDescriptorCollection. Then you can iterate
through the collection and get the value of each property using GetValue
function.

Form f = new Form();
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(f);
foreach(PropertyDescriptor p in props)
if ( p.GetValue(f) != null )
Console.WriteLine(p.GetValue.ToString(f));

best regards
Piotr Walczak
 
Back
Top