I have a generic C# interface as follows:
public interface ISerialiser<TV>
{
void Write( BinaryWriter output, TV value );
TV Read( BinaryReader input );
Type GetValueType();
}
of which I have several implementations, this being one of them:
public class BooleanSerialiser : ISerialiser<bool>
{
public void Write( BinaryWriter output, bool value )
{
output.Write( value );
}
public bool Read( BinaryReader input )
{
return input.ReadBoolean();
}
public Type GetValueType()
{
return typeof(bool);
}
}
This and the other implementations need to be added to a linked list - something like this:
private readonly LinkedHashMap<Type,ISerialiser<?>> theSerialisers =
new LinkedHashMap<Type, ISerialiser<?>>();
As you can see, I'm using the Java-style wildcard to signify that there are different types of serialiser to add - I realise this won't possibly compile in C# :)
My question is: how do I 'change things around' so that I'm able to populate the HashMap with whatever type of serialiser I wish, and call the interface methods in the same (or similar) way when I eventually pull the objects out of the HashMap?