Determine Type of Items in a collection

  • Thread starter Bud J via DotNetMonster.com
  • Start date
B

Bud J via DotNetMonster.com

what would be a good way to determine the type of objects in a collection.
For example, i have an orders collection , which inherits collectionbase and
implements ibindinglist, that contains a list of orders. So if i "inspect
the class" how could i determine that it is a collection of order objects. I
can accomplish this by using custom attributes but i really prefer something
like an abstract method so it will force anyone deriving from this class to
implement something for the collection type.
 
C

Claes Bergefall

I would use reflection and check out what type the Item property returns
This of course requires that the collection has a strongly typed Item
property
(which you should have if you inherit CollectionBase)

/claes
 

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