Class SerializationExtensions
- Namespace
- AiDotNet.Extensions
- Assembly
- AiDotNet.dll
Provides extension methods for serializing and deserializing data used in AI models.
public static class SerializationExtensions
- Inheritance
-
SerializationExtensions
- Inherited Members
Remarks
For Beginners: Serialization is the process of converting data structures or objects into a format that can be stored (in a file or database) or transmitted (across a network). Deserialization is the reverse process.
This class provides methods to save your AI model data to files and load them back later. Think of it like saving your progress in a video game so you can continue later.
Methods
ReadArray<T>(BinaryReader)
Reads an array of type T from a binary stream.
public static T[] ReadArray<T>(this BinaryReader reader)
Parameters
readerBinaryReaderThe binary reader to read from.
Returns
- T[]
An array of type T containing the deserialized data.
Type Parameters
TThe type of elements in the array.
Remarks
For Beginners: This method reads an array of values from a file or stream. It first reads how many items are in the array, then reads each item one by one.
For example, if you saved an array of weights from your AI model, this method helps you load those weights back.
ReadInt32Array(BinaryReader)
Reads an array of integers from a binary stream.
public static int[] ReadInt32Array(this BinaryReader reader)
Parameters
readerBinaryReaderThe binary reader to read from.
Returns
- int[]
An array of integers.
Remarks
For Beginners: This method is a specialized version that reads an array of whole numbers (integers) from a file or stream. It's optimized for integer arrays, which are commonly used in AI for things like neural network layer sizes, category indices, or feature counts.
For example, if your neural network has layers with sizes [784, 128, 64, 10], this method could help you load that structure from a saved file.
ReadValue(BinaryReader, Type)
Reads a value of the specified type from a binary stream.
public static object ReadValue(this BinaryReader reader, Type type)
Parameters
readerBinaryReaderThe binary reader to read from.
typeTypeThe type of value to read.
Returns
- object
The deserialized value as an object.
Remarks
For Beginners: This method reads a single value from a file or stream. It handles different types of values based on what type you specify.
Currently supported types are:
- int (whole numbers like 1, 2, 3)
- double (decimal numbers with high precision like 3.14159265359)
- float (decimal numbers with medium precision like 3.14)
- bool (true/false values)
Exceptions
- ArgumentException
Thrown when the specified type is not supported.
WriteArray<T>(BinaryWriter, T[])
Writes an array of type T to a binary stream.
public static void WriteArray<T>(this BinaryWriter writer, T[] array)
Parameters
writerBinaryWriterThe binary writer to write to.
arrayT[]The array to write.
Type Parameters
TThe type of elements in the array.
Remarks
For Beginners: This method saves an array of values to a file or stream. It first writes how many items are in the array, then writes each item one by one.
For example, if you want to save the weights of your AI model for later use, this method helps you do that.
WriteInt32Array(BinaryWriter, int[])
Writes an array of integers to a binary stream.
public static void WriteInt32Array(this BinaryWriter writer, int[] array)
Parameters
writerBinaryWriterThe binary writer to write to.
arrayint[]The array of integers to write.
Remarks
For Beginners: This method is a specialized version that saves an array of whole numbers (integers) to a file or stream. It's optimized for integer arrays, which are commonly used in AI for things like neural network layer sizes, category indices, or feature counts.
For example, if your neural network has layers with sizes [784, 128, 64, 10], this method could help you save that structure to a file.
WriteValue(BinaryWriter, object)
Writes a value of a supported type to a binary stream.
public static void WriteValue(this BinaryWriter writer, object value)
Parameters
writerBinaryWriterThe binary writer to write to.
valueobjectThe value to write.
Remarks
For Beginners: This method saves a single value to a file or stream. It handles different types of values (integers, decimals, true/false values) appropriately.
Currently supported types are:
- int (whole numbers like 1, 2, 3)
- double (decimal numbers with high precision like 3.14159265359)
- float (decimal numbers with medium precision like 3.14)
- bool (true/false values)
Exceptions
- ArgumentException
Thrown when the value's type is not supported.