Hey All,
I've asked this question yesterday and got lots of good answers, only I just realized my question was wrong and here I want to rephrase it.
I have this interface
public interface IFoo<T>
{
T Value();
}
With this members
public class Bar : IFoo<string>
{
string Value(){return "test";}
}
public class Bar2 : IFoo<int>
{
int Value(){return "1";}
}
This works perfectly, but now I want to make a class that has a property that can be either Bar or Bar2 so like this
public class Test
{
IFoo test;
}
Only this will not compile because Ifoo needs to have a generic type. Only I don't know in advance whether I will use Bar2 or Bar.
I hope I explained it well, but if not, I'll try to make it more clear.
Explaination
I'm trying (just for fun's sake) to create a Dicom api (medical imaging etc). Part of the dicom standard are some ValueRepresentations (VR's). These are types that are used to store (meta)information of the image.
Such VR's are for example: AgeString, Date, UnsignedShort, SequenceOfItems.
For all of these VR's I want to have some methods that all of them have to implement (encoding etc). But I all want them to be able to store a value. Whether this is a Int, or a DateTime or a String, shouldn't this be put in the Interface?