Table of Contents

Class SF

Namespace
SunamoSerializer
Assembly
SunamoSerializer.dll

Provides serialization and deserialization utilities for text-based data files with delimited content.

public static class SF
Inheritance
SF
Inherited Members

Fields

ReplaceForSeparatorChar

Replacement character used when separator character is found in content.

public static readonly char ReplaceForSeparatorChar

Field Value

char

ReplaceForSeparatorString

Replacement string used when separator character is found in content.

public const string ReplaceForSeparatorString = "_"

Field Value

string

Properties

DefaultDelimiter

Gets or sets the default delimiter used for serialization.

public static string DefaultDelimiter { get; set; }

Property Value

string

KeyCodeSeparator

Gets the key code of the separator character.

public static int KeyCodeSeparator { get; }

Property Value

int

SeparatorChar

Gets the separator character. Must be property to avoid inconsistency when changing value.

public static char SeparatorChar { get; }

Property Value

char

SeparatorString

Gets or sets the separator string used for serialization.

public static string SeparatorString { get; set; }

Property Value

string

Methods

AppendAllText(string, string)

Appends a line to a file and returns all parsed elements.

public static Task<List<List<string>>> AppendAllText(string filePath, string line)

Parameters

filePath string

Path to the file.

line string

The line to append.

Returns

Task<List<List<string>>>

All elements from the file after appending.

DictionaryAppend(string, Dictionary<int, string>)

Appends a dictionary to an existing file in serialized format.

public static Task DictionaryAppend(string filePath, Dictionary<int, string> dictionary)

Parameters

filePath string

Path to the file to append to.

dictionary Dictionary<int, string>

The dictionary to serialize and append.

Returns

Task

Dictionary<TKey, TValue>(string, Dictionary<TKey, TValue>)

Writes a dictionary to a file in serialized format.

public static Task Dictionary<TKey, TValue>(string filePath, Dictionary<TKey, TValue> dictionary) where TKey : notnull

Parameters

filePath string

Path to the output file.

dictionary Dictionary<TKey, TValue>

The dictionary to serialize and write.

Returns

Task

Type Parameters

TKey

The type of dictionary keys.

TValue

The type of dictionary values.

GetAllElementsFile(string)

Gets all elements from all lines of a file, with header included as first row.

public static List<List<string>> GetAllElementsFile(string filePath)

Parameters

filePath string

Path to the file to read.

Returns

List<List<string>>

List of element lists, where each inner list represents elements from one line.

GetAllElementsFile(string, string)

Gets all elements from all lines of a file using the specified separator.

public static List<List<string>> GetAllElementsFile(string filePath, string separator = "|")

Parameters

filePath string

Path to the file to read.

separator string

The separator string used between elements.

Returns

List<List<string>>

List of element lists, where each inner list represents elements from one line.

GetAllElementsFileAdvanced(string, string)

Gets all elements from a file, returning header and data rows separately.

public static (List<string> header, List<List<string>> rows) GetAllElementsFileAdvanced(string filePath, string separator = "|")

Parameters

filePath string

Path to the file to read.

separator string

The separator string used between elements. Defaults to "|".

Returns

(List<string> header, List<List<string>> rows)

A tuple containing the header elements and a list of row element lists.

GetAllElementsLine(string, string?)

Gets all elements from a single line using the specified separator.

public static List<string> GetAllElementsLine(string text, string? separator = null)

Parameters

text string

The line to parse.

separator string

The separator string used between elements. Defaults to "|".

Returns

List<string>

List of parsed elements from the line.

GetElementAtIndexFile(string, int, int)

Gets the element at specified indices from a file. Returns null if not found.

public static string? GetElementAtIndexFile(string filePath, int elementIndex, int lineIndex)

Parameters

filePath string

Path to the file to read.

elementIndex int

The element index within a line.

lineIndex int

The line index in the file.

Returns

string

The element at the specified position, or null if not found.

GetFirstWhereIsFirstElement(string, string)

Gets the first line where the first element matches the specified value. Returns null if not found.

public static List<string>? GetFirstWhereIsFirstElement(string filePath, string firstElement)

Parameters

filePath string

Path to the file to read.

firstElement string

The value to match against the first element of each line.

Returns

List<string>

The matching line as a list of elements, or null if not found.

GetLastWhereIsFirstElement(string, string)

Gets the last line where the first element matches the specified value. Returns null if not found.

public static List<string>? GetLastWhereIsFirstElement(string filePath, string firstElement)

Parameters

filePath string

Path to the file to read.

firstElement string

The value to match against the first element of each line.

Returns

List<string>

The matching line as a list of elements, or null if not found.

ListFromDictionary<TKey, TValue>(Dictionary<TKey, TValue>)

Converts a dictionary into a list of string lists for serialization.

public static List<List<string>> ListFromDictionary<TKey, TValue>(Dictionary<TKey, TValue> dictionary) where TKey : notnull

Parameters

dictionary Dictionary<TKey, TValue>

The dictionary to convert.

Returns

List<List<string>>

List of string lists where each inner list contains key and value as strings.

Type Parameters

TKey

The type of dictionary keys.

TValue

The type of dictionary values.

ParseUpToRequiredElementsLine(string, int)

Parses a line and ensures it contains exactly the required number of elements, padding with empty strings if needed.

public static List<string> ParseUpToRequiredElementsLine(string text, int requiredCount)

Parameters

text string

The input line to parse.

requiredCount int

The required number of elements.

Returns

List<string>

List of parsed elements with exactly requiredCount items.

PrepareToSerialization(List<string>, string)

Serializes a list of strings into a single delimited line.

public static string PrepareToSerialization(List<string> list, string separator = "|")

Parameters

list List<string>

The list of strings to serialize.

separator string

The separator string to use between elements.

Returns

string

A delimited string containing all elements.

PrepareToSerialization(params string[])

Serializes string elements into a single delimited line using the default delimiter.

public static string PrepareToSerialization(params string[] elements)

Parameters

elements string[]

The elements to serialize.

Returns

string

A delimited string containing all elements.

ReadFileOfSettingsOther(string, Func<string, string>)

Reads a settings file and extracts the separator from its first line.

public static void ReadFileOfSettingsOther(string filePath, Func<string, string> readFileFunc)

Parameters

filePath string

Path or name of the settings file.

readFileFunc Func<string, string>

Function that resolves the file path and reads its content.

RemoveComments(List<string>)

Removes comment lines (starting with #) and whitespace-only lines from the input.

public static List<string> RemoveComments(List<string> list)

Parameters

list List<string>

The list of lines to filter.

Returns

List<string>

Filtered list with comments and empty lines removed.

ToDictionary<TKey, TValue>(List<List<string>>)

Converts a list of string element lists into a dictionary by parsing each pair.

public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(List<List<string>> list) where TKey : notnull

Parameters

list List<List<string>>

The list of string element lists where each inner list should have exactly 2 elements.

Returns

Dictionary<TKey, TValue>

Dictionary populated from the parsed elements.

Type Parameters

TKey

The type of dictionary keys.

TValue

The type of dictionary values.

WriteAllElementsToFile(string, List<List<string>>)

Writes all element lists to a file in serialized format.

public static Task WriteAllElementsToFile(string filePath, List<List<string>> list)

Parameters

filePath string

Path to the output file.

list List<List<string>>

The list of element lists to serialize and write.

Returns

Task

WriteAllElementsToFile(string, List<string>[])

Writes all element arrays to a file in serialized format.

public static Task WriteAllElementsToFile(string filePath, List<string>[] array)

Parameters

filePath string

Path to the output file.

array List<string>[]

Array of element lists to serialize and write.

Returns

Task

WriteAllElementsToFile<TKey, TValue>(string, Dictionary<TKey, TValue>)

Writes all elements from a dictionary to a file in serialized format.

public static Task WriteAllElementsToFile<TKey, TValue>(string filePath, Dictionary<TKey, TValue> dictionary) where TKey : notnull

Parameters

filePath string

Path to the output file.

dictionary Dictionary<TKey, TValue>

The dictionary to serialize and write.

Returns

Task

Type Parameters

TKey

The type of dictionary keys.

TValue

The type of dictionary values.