Class BasicRecordStore
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
An abstract base class for key-value record stores.
public abstract class BasicRecordStore
- Inheritance
-
BasicRecordStore
- Derived
- Inherited Members
Remarks
This class defines a common interface for record manipulation (add, remove, enumerate, etc.) and provides a generic, reflection-based serialization mechanism that dispatches to the static methods of the concrete derived class.
Methods
Add(int)
Adds a record with the specified identifier, or returns false if it already exists.
public virtual bool Add(int identifier)
Parameters
identifierintThe identifier of the record to add.
Returns
- bool
true if a new record was added; false if a record with that identifier already existed.
Clear()
When overridden in a derived class, removes all records from the store.
public virtual void Clear()
Contains(int)
When overridden in a derived class, determines whether a record with the specified identifier exists.
public virtual bool Contains(int identifier)
Parameters
identifierintThe identifier to locate.
Returns
- bool
true if a record with the specified identifier is found; otherwise, false.
Deserialize<T>(byte[])
Deserializes a store from a byte array.
public static T Deserialize<T>(byte[] data) where T : BasicRecordStore
Parameters
databyte[]The byte array containing the serialized data.
Returns
- T
A new instance of
T.
Type Parameters
TThe concrete type of the record store to deserialize, which must have a public static
Deserialize(Stream)method.
Remarks
This static method uses reflection to invoke the static Deserialize(Stream) method on the specified type T.
Exceptions
- ArgumentNullException
datais null.
Deserialize<T>(Stream)
Deserializes a store from a stream using reflection.
public static T Deserialize<T>(Stream stream) where T : BasicRecordStore
Parameters
streamStreamThe stream to read the serialized data from.
Returns
- T
A new instance of
T.
Type Parameters
TThe concrete type of the record store to deserialize, which must have a public static
Deserialize(Stream)method.
Exceptions
- ArgumentNullException
streamis null.- NotSupportedException
The type
Tdoes not have a public staticDeserialize(Stream)method.
Deserialize<T>(string)
Deserializes a store from a file.
public static T Deserialize<T>(string file) where T : BasicRecordStore
Parameters
filestringThe path of the file to read from.
Returns
- T
A new instance of
T.
Type Parameters
TThe concrete type of the record store to deserialize, which must have a public static
Deserialize(Stream)method.
Remarks
This static method uses reflection to invoke the static Deserialize(Stream) method on the specified type T.
Exceptions
- ArgumentNullException
fileis null.- ArgumentException
fileis empty or whitespace.
Enumerate()
When overridden in a derived class, returns an enumerator that iterates through all records in the store.
public virtual IEnumerable<(int, BasicRecordStore.RecordAccess)> Enumerate()
Returns
- IEnumerable<(int, BasicRecordStore.RecordAccess)>
An IEnumerable<T> of tuples, each containing an identifier and its corresponding BasicRecordStore.RecordAccess.
GetRecordAccess(int)
Gets the accessor for a record with the specified identifier. If the record does not exist, it is created.
public virtual BasicRecordStore.RecordAccess GetRecordAccess(int identifier)
Parameters
identifierintThe identifier of the record to get or create.
Returns
- BasicRecordStore.RecordAccess
A BasicRecordStore.RecordAccess for the found or newly created record.
GetRecordAccess(int, out bool)
When overridden in a derived class, gets the accessor for a record with the specified identifier, indicating if it was newly created.
public virtual BasicRecordStore.RecordAccess GetRecordAccess(int identifier, out bool createNew)
Parameters
identifierintThe identifier of the record to get or create.
createNewboolWhen this method returns, contains true if a new record was created; otherwise, false.
Returns
- BasicRecordStore.RecordAccess
A BasicRecordStore.RecordAccess for the found or newly created record.
Remove(int)
When overridden in a derived class, removes a record with the specified identifier.
public virtual void Remove(int identifier)
Parameters
identifierintThe identifier of the record to remove.
Serialize<T>(T, SerializationOptions?)
Serializes the specified store instance into a byte array.
public static byte[] Serialize<T>(T obj, BasicRecordStore.SerializationOptions? options = null) where T : BasicRecordStore
Parameters
objTThe record store instance to serialize.
optionsBasicRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Returns
- byte[]
A byte array containing the serialized data.
Type Parameters
TThe concrete type of the record store, which must have a public static
Serialize(T, Stream)method.
Remarks
This static method uses reflection to invoke the static Serialize(T, Stream) method on the actual type of obj.
Exceptions
- ArgumentNullException
objis null.
Serialize<T>(T, Stream, SerializationOptions?)
Serializes the specified store instance into a stream using reflection.
public static void Serialize<T>(T obj, Stream stream, BasicRecordStore.SerializationOptions? options = null) where T : BasicRecordStore
Parameters
objTThe record store instance to serialize.
streamStreamThe stream to write the serialized data to.
optionsBasicRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Type Parameters
TThe concrete type of the record store, which must have a public static
Serialize(T, Stream)method.
Exceptions
- ArgumentNullException
objorstreamis null.- NotSupportedException
The type
Tdoes not have a public staticSerialize(T, Stream)method.
Serialize<T>(T, string, SerializationOptions?)
Serializes the specified store instance to a file.
public static void Serialize<T>(T obj, string file, BasicRecordStore.SerializationOptions? options = null) where T : BasicRecordStore
Parameters
objTThe record store instance to serialize.
filestringThe path of the file to create.
optionsBasicRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Type Parameters
TThe concrete type of the record store, which must have a public static
Serialize(T, Stream)method.
Remarks
This static method uses reflection to invoke the static Serialize(T, Stream) method on the actual type of obj.
Exceptions
- ArgumentNullException
objorfileis null.- ArgumentException
fileis empty or whitespace.
TryGetRecordAccess(int, out RecordAccess?)
When overridden in a derived class, tries to get the accessor for a record with the specified identifier.
public virtual bool TryGetRecordAccess(int identifier, out BasicRecordStore.RecordAccess? access)
Parameters
identifierintThe identifier to locate.
accessBasicRecordStore.RecordAccessWhen this method returns, contains the BasicRecordStore.RecordAccess object if the identifier was found; otherwise, null.
Returns
- bool
true if a record with the specified identifier was found; otherwise, false.