Search all the browsable attributes of an object.

M

Mr. X.

Hello.
I would like to search by reflection all the properties, but only properties
that can be seen on PropertyGrid class (exact match).
Need sample, please.

Thanks :)
 
M

Mr. X.

I do
System.Reflection.PropertyInfo[] prs =
MyControl.GetType().getProperties(BindingFlags.Public |
BindingFlags.Instance);
foreach (PropertyInfo pi in prs)
{
if IsBrowsable(pi)
{
...
}
}

public bool IsBrowsable(PropertyInfo p)
{
bool res;
res = true;
foreach (object att_loopVariable in p.GetCustomAttributes(true))
{
if (att_loopVariable is
System.ComponentModel.BrowsableAttribute)
{
System.ComponentModel.BrowsableAttribute att;
att =
(System.ComponentModel.BrowsableAttribute)att_loopVariable;
if (!(att as
System.ComponentModel.BrowsableAttribute).Browsable)
{
res = false;
}
}
}
return res;
}

*****
The above is not the exact match as I look at propertyGrid that attached to
MyControl.

1. Is the line System.Reflection.PropertyInfo[] prs =
MyControl.GetType().getProperties(BindingFlags.Public |
BindingFlags.Instance) correct ?
2. Is IsBrowsable correct?

What should I write in order to have the proper code.

Thanks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top