Table of Contents

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

identifier int

The 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

identifier int

The 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

data byte[]

The byte array containing the serialized data.

Returns

T

A new instance of T.

Type Parameters

T

The 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

data is null.

Deserialize<T>(Stream)

Deserializes a store from a stream using reflection.

public static T Deserialize<T>(Stream stream) where T : BasicRecordStore

Parameters

stream Stream

The stream to read the serialized data from.

Returns

T

A new instance of T.

Type Parameters

T

The concrete type of the record store to deserialize, which must have a public static Deserialize(Stream) method.

Exceptions

ArgumentNullException

stream is null.

NotSupportedException

The type T does not have a public static Deserialize(Stream) method.

Deserialize<T>(string)

Deserializes a store from a file.

public static T Deserialize<T>(string file) where T : BasicRecordStore

Parameters

file string

The path of the file to read from.

Returns

T

A new instance of T.

Type Parameters

T

The 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

file is null.

ArgumentException

file is 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

identifier int

The 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

identifier int

The identifier of the record to get or create.

createNew bool

When 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

identifier int

The 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

obj T

The record store instance to serialize.

options BasicRecordStore.SerializationOptions

Options 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

T

The 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

obj is 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

obj T

The record store instance to serialize.

stream Stream

The stream to write the serialized data to.

options BasicRecordStore.SerializationOptions

Options to control the serialization process. If null, the settings from Default will be used.

Type Parameters

T

The concrete type of the record store, which must have a public static Serialize(T, Stream) method.

Exceptions

ArgumentNullException

obj or stream is null.

NotSupportedException

The type T does not have a public static Serialize(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

obj T

The record store instance to serialize.

file string

The path of the file to create.

options BasicRecordStore.SerializationOptions

Options to control the serialization process. If null, the settings from Default will be used.

Type Parameters

T

The 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

obj or file is null.

ArgumentException

file is 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

identifier int

The identifier to locate.

access BasicRecordStore.RecordAccess

When 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.