C
colin
Hi,
If i have a set of overloaded serialization routines such as
void Serialize(ref Int32 x);
void Serialize<T>(ref T x);
this works great,... when I call the function with an int32 it calls the
first one,
any other type it calls the second one.
however If i have a serializer for a generic array
void SerializeArray<T>(ref T[] array)
{
for(int x...)
Serialize(ref array[x]);
}
it always calls the generic function even if its an array of ints,
how do i get round this so it calls the first one if its an array of ints
wothout doing a test to see if its one of the many diferent types ?
the generic function is going to be slow, probably using reflection,
so I want to call it only for complex classes or ones wich dont apear very
often,
but for all the system types and a few often used structs/classes
I want to call specific functions.
so whats the best way to implement the array serializer,
without writing a seperate one for all the system types?
I also need to have several diferent types of array serializers as some use
one of two forms of storage.
some data types need to be serialized diferently ie some int64 are packed so
that the most significant
bytes arnt stored if they are zero (or 255 for negative numbers). with
arrays of these types too.
Colin =^.^=
If i have a set of overloaded serialization routines such as
void Serialize(ref Int32 x);
void Serialize<T>(ref T x);
this works great,... when I call the function with an int32 it calls the
first one,
any other type it calls the second one.
however If i have a serializer for a generic array
void SerializeArray<T>(ref T[] array)
{
for(int x...)
Serialize(ref array[x]);
}
it always calls the generic function even if its an array of ints,
how do i get round this so it calls the first one if its an array of ints
wothout doing a test to see if its one of the many diferent types ?
the generic function is going to be slow, probably using reflection,
so I want to call it only for complex classes or ones wich dont apear very
often,
but for all the system types and a few often used structs/classes
I want to call specific functions.
so whats the best way to implement the array serializer,
without writing a seperate one for all the system types?
I also need to have several diferent types of array serializers as some use
one of two forms of storage.
some data types need to be serialized diferently ie some int64 are packed so
that the most significant
bytes arnt stored if they are zero (or 255 for negative numbers). with
arrays of these types too.
Colin =^.^=