Determine Type of Items in a collection

  • Thread starter Thread starter Bud J via DotNetMonster.com
  • Start date 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.
 
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
 
Back
Top