iterate through object attributes

  • Thread starter Thread starter Fabian
  • Start date Start date
F

Fabian

Hi,

I would like to iterate attributes of an object like

foreach(attribute a in o.attributes)
{
...
}

any way i can do that?

Thanks
Fabian
 
Hi Fabian,

You can do that

Type objType = o.GetType();

foreach(Attribute attrib in objType.GetCustomAttributes(....))
{
.....
}

Look at MSDN about GetCustomAttributes parameters
 
use TypeDescriptor.

foreach(Attribute a in TypeDescriptor.GetAttributes(o.GetType()))
{
...
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Back
Top