wentz__ wentz__ - 1 year ago 110
C# Question

C# Reflection How-to?

I'm having trouble grasping reflection in C#, so I'm going to put my specific situation down and see what you guys can come up with. I've read TONS of C# reflection questions on here, but I still just simply don't get it.

So here's my situation; I'm trying to access an array which is a non-public member of a class I have access to.

alt text

Basically it's a System.Collections.CollectionBase which has an array variable called "list", but it has this parent type of OrderCollection and the reflection of it is just confusing the hell out of me.

I have to do a lot of these so a good guide or example would really help. Please let me know if you would like more information.

I blacked out the name of the namespace not because what I'm doing is not illegal by any means, but I'm trying to be first to market on this and so I'm trying to be careful.

Answer Source

What are you trying to use reflection at all? CollectionBase supports indexing, but only through the explicit interface implementation of IList, so you ought to be able to write:

IList list = Acct.Orders;
response = list[0];

You may need to cast the result to a more appropriate type, but I don't see any need for reflection here.

EDIT: Original answer didn't take account of explicit interface implementation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download