I have a DICOM dictionary that contains a set of objects all deriving from DataElement.
The dictionary has an int as a key, and the DataElement as property.
My DICOM dictionary contains a this[] property where I can access the DataElement, like this:
public class DicomDictionary
{
Dictionary<int, DataElement> myElements = new Dictionary<int, DataElement>();
.
.
public DataElement this[int DataElementTag]
{
get
{
return myElements[int];
}
}
}
A problem now is that I have different DataElement types all deriving from DataElement, like DataElementSQ, DataElementOB and so on. What I wanted to do now is the following to make writing in C# a little bit easier:
public T this<T>[int DataElementTag] where T : DataElement
{
get
{
return myElements[int];
}
}
But this is not really possible. Is there something I have missed? Of course I could do it with Getter method, but it would be much nicer to have it this way.
Why not use a real generic method
GetDataElement<T> where T : DataElementinstead? Generic indexers are not supported in C#. Why do you think in this case an indexer is better than a method?