BinarySerializerSerializeValueArrayT Method

Serializes an Array of ValueType elements into a byte array.

Definition

Namespace: KGySoft.Serialization.Binary
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.5.0
C#
[SecurityCriticalAttribute]
public static byte[] SerializeValueArray<T>(
	T[] array
)
where T : struct, new()

Parameters

array  T
The array to serialize.

Type Parameters

T
Element type of the array. Must be a ValueType that has no references.

Return Value

Byte
The byte array representation of the array.

Remarks

  Security Note

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.

  Caution

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.

See Also