BinarySerializerSerializeValueArrayT Method
Namespace: KGySoft.Serialization.BinaryAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.5.0
[SecurityCriticalAttribute]
public static byte[] SerializeValueArray<T>(
T[] array
)
where T : struct, new()
<SecurityCriticalAttribute>
Public Shared Function SerializeValueArray(Of T As {Structure, New}) (
array As T()
) As Byte()
public:
[SecurityCriticalAttribute]
generic<typename T>
where T : value class, gcnew()
static array<unsigned char>^ SerializeValueArray(
array<T>^ array
)
[<SecurityCriticalAttribute>]
static member SerializeValueArray :
array : 'T[] -> byte[] when 'T : struct, new()
- array T
- The array to serialize.
- T
- Element type of the array. Must be a ValueType that has no references.
ByteThe byte array representation of the
array.
Do not use this method with
T types that have references.
When using this library with a compiler that recognizes the
unmanaged constraint,
then this is enforced for direct calls; however, by using reflection
T can be any value type.
For performance reasons this method does not check if
T has references,
but you can call the
TrySerializeValueArrayT(T, Byte) method that performs the check.
If packing is not defined on the type of
T by
StructLayoutAttribute.Pack,
or it contains pointers or native-sized integer fields, then the length of the result might be different on 32 and 64-bit systems.
The serialized content depends also on the endianness of the executing architecture, and if there are gaps between the fields,
the serialized data will contain these gaps. Therefore, it is generally not recommended to deserialize the result in a potentially different environment,
or to store the serialized data in a file or database, for example.