469,576 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,576 developers. It's quick & easy.

How can i get the Property value using Reflection (Return type: Collection of controls)

i want to get the property value using reflection.

Scenerio:
i have a status bar on MDI form. it has property named "Panels" and i want
to get a specific panel from that
panels collection using reflection.
Please let me know.

Thanks
C# Developer
Mudassar
Nov 17 '05 #1
1 24007
Funny you should ask today. There's been a lot of reflection going on in our
office today. Here's a sample of getting a field:

string dataField;
FieldInfo fi = currentManager.GetType().GetField("dataField",
BindingFlags.NonPublic | BindingFlags.Instance);
dataField = (string) fi.GetValue(currentManager);
Basically, you'll want to get ProeprtyInfo instead of a FieldInfo (using
GetProperty()), but otherwise it's more or less the same.

In this case, currentManager is a "CurrencyManager" object and "dataField"
is a private field in the CurrencyManager.

The key is to make sure your BindingFlags values are correct. These should
work for non-public instance fields. If it's static or public (I doubt it's
public, otherwise why use reflection, right?), make the appropriate changes.

Hope that helps.

Pete
"Mudassar" <mu******@nxb.com.pk> wrote in message
news:ux**************@TK2MSFTNGP14.phx.gbl...
i want to get the property value using reflection.

Scenerio:
i have a status bar on MDI form. it has property named "Panels" and i want to get a specific panel from that
panels collection using reflection.
Please let me know.

Thanks
C# Developer
Mudassar

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by MP | last post: by
6 posts views Thread by Altman | last post: by
reply views Thread by Rene Aichinger | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.