Guys,
I realize this is not possible with either VB or C#, but I would like to get
some opinions on the validity or invalidity to these constructs.
What I'm proposing is the ability to have Generic properties (in addition to
methods) and as a result, also have generic indexers.
I have, in the course of my development over the past month, come across
situations where both would be useful and allow me to "abstract" certain
functionality to a base class instead of having to place that functionality
in each object that needs it.
Generic Indexer Example:
public MyObject this<ItemType>[ItemType index]{
//Some function that converts ItemType to the appropriate index or other
look-up.
}
What this does is give me the ability to look up items in a list (especially
useful or look-up operations) using a specific type of data instead of a
pre-defined type of data, regardless of the "type" that the collection is.
In doing research and development, I've been able to utilize Attributes
along side generic methods to map Enums to Guids. This allows a guid to
represent a look-up table and still use an Enum to represent the Guid. So,
in the aforementioned example, I can pass in my "generic" enum and have that
conversion occur to replace the enum with the guid and thereby allow
an indexer to work the same way, but with a different data type each time.
I can now put that indexer in the base collection class (instead of my
derived collection classes) and use it when appropriate.
Any ideas or comments?
Thanks,
Mike
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com