I wrote a serializer (to Byte Array) for dictionaries that have a string key, but an object of some sort as its value.
I've never implemented a generic type in a function or used a delegate before, so I'm a bit concerned about this being significantly slower than writing a serialization function for a specific type of Dictionary (Dictionary(Of String, MyClass) for example).
Should this code be significantly slower due to the use of the generic type or the delegate?
Public Delegate Function Serializer(Of T)(ByRef Obj As T) As Byte()
Function SerializeDictionary_String_Object(Of T)(ByRef D As Dictionary(Of String, T), ByVal S As Serializer(Of T)) As Byte()
Dim OBJ As T
For Each X In D
OBJ = X.Value
Exit For
Next
Return S(OBJ)
End Function
Here's some code that uses this:
SerializeDictionary_String_Object(Of MyClass)(MyDictionary, AddressOf MyClass.Serialize)
It works, and I could loop it and compare it to a more static Dictionary serializer, but I'm more concerned about when I start using this for a lot of different String/Object dictionary combinations, and it'll take me a long time to write a bunch of static dictionary serializers (that's what I'm hoping to avoid in the first place)
edit: simplified intro text