Reflection

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

Is it possible to use reflection to get a list of the
properties in a class to which I have applied a particular
attribute? I want to get all of the properties to which I
have applied the Browsable attribute. I will also need
their data types.
 
Something like this:


class MySpecialPropertyAttribute: Attribute
{
...
}

class YourClass
{
[MySpecialProperty]
public string MyProp { get ... set. }
...
}

Type t = typeof(YourClass);
foreach( PropertyInfo pi in t.GetProperties() )
{
Attribute[] col = pi.GetCustomAttributes(typeof(MySpecialProperty),
false);
if ( col.Length > 0 )
{
// Do something
}
}
 
Thanks. I'll give it a try.

-----Original Message-----
Something like this:


class MySpecialPropertyAttribute: Attribute
{
...
}

class YourClass
{
[MySpecialProperty]
public string MyProp { get ... set. }
...
}

Type t = typeof(YourClass);
foreach( PropertyInfo pi in t.GetProperties() )
{
Attribute[] col = pi.GetCustomAttributes(typeof (MySpecialProperty),
false);
if ( col.Length > 0 )
{
// Do something
}
}

Steven said:
Is it possible to use reflection to get a list of the
properties in a class to which I have applied a particular
attribute? I want to get all of the properties to which I
have applied the Browsable attribute. I will also need
their data types.


.
 
Back
Top