Enumerating a protected class

G

Glen

Hello,

Can anyone tell me if there is a way to enumerate a member collection
for a protected class? For example, the Cursors class is protected and
must be called directly, but it does not contain a method to enumerate
the Cursor collection in the class. Since it is protected, I don't
believe I can use the standard Reflection methods to retrieve the member
info unless there is something I'm overlooking.

I don't necessarily want to enumerate the Cursors class, but I'm sure
this type of situation will show up again with another protected class
and I'd like to know how to handle it, if it's possible.

Any insight would be greatly appreciated.

- Glen
 
D

Daniel O'Connell [C# MVP]

Glen said:
Hello,

Can anyone tell me if there is a way to enumerate a member collection for
a protected class? For example, the Cursors class is protected and must
be called directly, but it does not contain a method to enumerate the
Cursor collection in the class. Since it is protected, I don't believe I
can use the standard Reflection methods to retrieve the member info unless
there is something I'm overlooking.

I don't necessarily want to enumerate the Cursors class, but I'm sure this
type of situation will show up again with another protected class and I'd
like to know how to handle it, if it's possible.

I don't think Cursors has a cursor collection. What specifically are you
talking about?
 
G

Glen

Hi Daniel,

Basically what I'm looking to do is create a collection of methods,
properties, fields, etc from the protected class. The cursor class is a
good example since it doesn't have a cursors collection, but it does
have a collection of properties of type "cursor". So basically, with
this example, I'm looking to dynamically create an array of the
properties who's type is cursor without having to know each property
explicitly.

The example comes from a book I was reading "C# Complete" by Sybex where
an array of cursors was used in some sample code. The array was
manually created naming each of the cursor objects explicitly, and I
thought that there must be a better way to handle this through a
collection iteration method.

I can get a collection of the PropertyInfo with type of cursor from the
class, but I can't seem to figure out how to cast the PropertyInfo type
back to the cursor type.

Any thoughts?

- Glen
 
D

Daniel O'Connell [C# MVP]

Glen said:
Hi Daniel,

Basically what I'm looking to do is create a collection of methods,
properties, fields, etc from the protected class. The cursor class is a
good example since it doesn't have a cursors collection, but it does have
a collection of properties of type "cursor". So basically, with this
example, I'm looking to dynamically create an array of the properties
who's type is cursor without having to know each property explicitly.

The example comes from a book I was reading "C# Complete" by Sybex where
an array of cursors was used in some sample code. The array was manually
created naming each of the cursor objects explicitly, and I thought that
there must be a better way to handle this through a collection iteration
method.

I can get a collection of the PropertyInfo with type of cursor from the
class, but I can't seem to figure out how to cast the PropertyInfo type
back to the cursor type.

Any thoughts?

Ahh, I see. Basically you need to call GetValue() on PropertyInfo and cast
the return value to Cursor.
 
G

Glen

You SO rock! :~)- The GetValue(null, null) call on the PropertyInfo
created the collection I was looking for. Now I just need to test it on
the MethodInfo and FieldInfo classes and put together the enumerator
methods and I'll be all set.

Thanks for all your help.

- Glen
 

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