I'm writing a generic DataStructure<T>
which persists on the disk, and I need to write it such that T
is guaranteed to be serializable in a fixed number of bytes. For example, int
and char
should be accepted, but string
or int[]
should not be. Likewise, a struct
with a string
member is not acceptable, but an unsafe struct
with a fixed char
array is.
I could write a runtime test in the initializer using reflection and sizeof
to test each member, but that seems like a terrible hack. Is there any efficient and (relatively) safe way to do this?