Core Library

Core utilities and helper functions for general C# development


OmegaLeo.HelperLib

ArrayExtensions

OmegaLeo.HelperLib
Member Documentation
Array Extensions

Set of extension methods to help with Arrays.


Next

Method to obtain the next object in the array by passing the current index. Note: Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302


Returns: T
Parameters:
  • array: T[]
  • currentIndex: ref int
Attribute Args:
  • CurrentIndex - The index we're currently on inside the array passed as reference so we can automatically assign to it the next index

BenchmarkUtility

OmegaLeo.HelperLib
Member Documentation
BenchmarkUtility

Utility class for benchmarking code execution time.


Example:
BenchmarkUtility.Start("MyBenchmark");
// Code to benchmark
BenchmarkUtility.Stop("MyBenchmark");
var results = BenchmarkUtility.GetResults("MyBenchmark");
Record

Records the execution time of the provided action and returns the elapsed time in milliseconds.


Returns: long
Parameters:
  • actionToRecord: Action
Example:
var time = BenchmarkUtility.Record(() =>
{
    // Code to benchmark
});

Console.WriteLine($"Elapsed time: {time} ms");
RecordAndSaveToResults

Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.


Returns: long
Parameters:
  • key: string
  • actionToRecord: Action
Example:
var time = BenchmarkUtility.RecordAndSaveToResults("MyBenchmark", () =>
{
    // Code to benchmark
});

Console.WriteLine($"Elapsed time: {time} ms");

var results = BenchmarkUtility.GetResults("MyBenchmark");

var averageTime = results.Average();
Console.WriteLine($"Average time: {averageTime} ms");
Start

Starts or restarts the stopwatch for the given key.


Returns: void
Parameters:
  • key: string
Stop

Stops the stopwatch for the given key and records the elapsed time.


Returns: void
Parameters:
  • key: string
GetResults

Retrieves the list of recorded times for the given key.


Returns: List<long>
Parameters:
  • key: string
ClearResults

Clears all recorded benchmark results.


Returns: void
GetAllResults

Retrieves all recorded benchmark results.


Returns: Dictionary<string, List<long>>

FloatExtensions

OmegaLeo.HelperLib
Member Documentation
FloatExtensions

Provides extension methods for the float data type.


Round

Rounds a float value to the specified number of decimal places.


Returns: float
Parameters:
  • value: float
  • digits: int
Attribute Args:
  • value: The float value to round.
  • digits: The number of decimal places to round to. Default is 2.
Example:
var originalValue = 3.14159f;
var roundedValue = originalValue.Round(2); // roundedValue will be 3.14
RoundToInt

Rounds a float value to the nearest integer and returns it as an int.


Returns: int
Parameters:
  • value: float
Attribute Args:
  • value: The float value to round.
Example:
var originalValue = 3.14159f;
var roundedValue = originalValue.RoundToInt(); // roundedValue will be 3

IListExtensions

OmegaLeo.HelperLib
Member Documentation
IListExtensions

Extension methods for IList to provide additional functionalities such as swapping, replacing, random selection, and shuffling.


Swap

Swaps the elements at the specified indices in the list.


Returns: IList<T>
Parameters:
  • list: IList<T>
  • indexA: int
  • indexB: int
Attribute Args:
  • list: The list in which to swap elements.
  • indexA: The index of the first element to swap.
  • indexB: The index of the second element to swap.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
myList.Swap(0, 2); // myList is now { 3, 2, 1, 4 }
Swap

Swaps the elements at the specified indices in the list.


Returns: IList<T>
Parameters:
  • list: IList<T>
  • itemA: T
  • itemB: T
Attribute Args:
  • list: The list in which to swap elements.
  • indexA: The index of the first element to swap.
  • indexB: The index of the second element to swap.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
myList.Swap(0, 2); // myList is now { 3, 2, 1, 4 }
Replace

Replaces the first occurrence of a specified value in the list with a new value.


Returns: IList<T>
Parameters:
  • list: IList<T>
  • originalValue: T
  • valueToReplace: T
Attribute Args:
  • list: The list in which to replace an element.
  • originalValue: The value to be replaced.
  • valueToReplace: The new value to insert.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
myList.Replace(2, 5); // myList is now { 1, 5, 3, 4 }
Random

Selects a random element from the list.


Returns: T
Parameters:
  • list: IList<T>
Attribute Args:
  • list: The list from which to select a random element.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
var randomElement = myList.Random(); // randomElement could be any of 1, 2, 3, or 4
Random

Selects a specified number of unique random elements from the list.


Returns: List<T>
Parameters:
  • list: IList<T>
  • count: int
Attribute Args:
  • list: The list from which to select random elements.
  • count: The number of unique random elements to select.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
var randomElements = myList.Random(2); // randomElements could be any two of 1, 2, 3, or 4
Next<T>

Method to obtain the next object in the list by passing the current index.


Returns: T
Parameters:
  • array: List<T>
  • currentIndex: ref int
Attribute Args:
  • CurrentIndex - The index we're currently on inside the list passed as reference so we can automatically assign to it the next index
Example:
var myList = new List<int> { 1, 2, 3,4 };
var currentIndex = 0;
var nextItem = myList.Next(ref currentIndex); // nextItem will be 1, currentIndex will be 1
var nextItem2 = myList.Next(ref currentIndex); // nextItem2 will be 2, currentIndex will be 2
Shuffle<T>

Shuffles the elements of the list in place using a cryptographic random number generator.

Code obtained from https://stackoverflow.com/a/1262619


Returns: IList<T>
Parameters:
  • list: IList<T>
Attribute Args:
  • list: The list to be shuffled.
Example:
var myList = new List<int> { 1, 2, 3, 4 };
myList.Shuffle(); // myList could now be { 3, 1, 4, 2 } (example output)

InstancedObject`1

OmegaLeo.HelperLib
Member Documentation
InstancedObject<T> Class

A generic base class that ensures only one instance of a derived class exists at any time.


Attribute Args:
  • T: The type of the derived class.
Example:
public class MySingleton : InstancedObject<MySingleton> 
{ 
    // Your class implementation here
}

MathExtensions

OmegaLeo.HelperLib
Member Documentation
MathExtensions

Provides extension methods for mathematical operations.


AverageWithNullValidation

Calculates the average of a list of integers, returning 0 if the list is empty.


Returns: int
Parameters:
  • list: IEnumerable<int>
Attribute Args:
  • list: The list of integers to calculate the average from.
Example:
var numbers = new List<int> { 1, 2, 3, 4 };
int average = numbers.AverageWithNullValidation(); // average will be 2 (rounded down)
var emptyList = new List<int>();
int averageEmpty = emptyList.AverageWithNullValidation(); // averageEmpty will be 0
AverageWithNullValidation

Calculates the average of a list of doubles, returning 0.0 if the list is empty.


Returns: double
Parameters:
  • list: IEnumerable<double>
Attribute Args:
  • list: The list of doubles to calculate the average from.
Example:
var numbers = new List<double> { 1.5, 2.5, 3.5 };
double average = numbers.AverageWithNullValidation(); // average will be 2.5
var emptyList = new List<double>();
double averageEmpty = emptyList.AverageWithNullValidation(); // averageEmpty will be 0.0
AverageWithNullValidation

Calculates the average of a list of floats, returning 0.0f if the list is empty.


Returns: float
Parameters:
  • list: IEnumerable<float>
Attribute Args:
  • list: The list of floats to calculate the average from.
Example:
var numbers = new List<float> { 1.5f, 2.5f, 3.5f };
float average = numbers.AverageWithNullValidation(); // average will be 2.5f
var emptyList = new List<float>();
float averageEmpty = emptyList.AverageWithNullValidation(); // averageEmpty will be 0.0f

NeoDictionary`2

OmegaLeo.HelperLib
Member Documentation
NeoDictionary

Dictionary like class created to make it easier to display dictionaries in game engines like Unity


TryGetValue

Tries to get the value from the NeoDictionary for the given key.


Returns: bool
Parameters:
  • key: TKey
  • value: out TValue
TryGetValueFromIndex

Tries to get the value from the NeoDictionary at the given index.


Returns: bool
Parameters:
  • index: int
  • value: out TValue
Add

Adds a new NeoDictionaryItem to the NeoDictionary.


Returns: void
Parameters:
  • key: TKey
  • value: TValue
AddRange

Adds a range of NeoDictionaryItems from another NeoDictionary to the NeoDictionary.


Returns: void
Parameters:
  • values: NeoDictionary<TKey, TValue>
AddRange

Adds a range of NeoDictionaryItems to the NeoDictionary.


Returns: void
Parameters:
  • values: IEnumerable<NeoDictionaryItem<TKey, TValue>>
Any

Checks if the NeoDictionary has any items.


Returns: bool
Any

Checks if any item in the NeoDictionary satisfies a condition.


Returns: bool
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
Where

Filters the NeoDictionary items based on a predicate.


Returns: IEnumerable<NeoDictionaryItem<TKey, TValue>>
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
FirstOrDefault

Returns the first item of the NeoDictionary or a default value if the NeoDictionary is empty.


Returns: NeoDictionaryItem<TKey, TValue>
FirstOrDefault

Returns the first item of the NeoDictionary that satisfies a condition or a default value if no such item is found.


Returns: NeoDictionaryItem<TKey, TValue>
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
LastOrDefault

Returns the last item of the NeoDictionary or a default value if the NeoDictionary is empty.


Returns: NeoDictionaryItem<TKey, TValue>
LastOrDefault

Returns the last item of the NeoDictionary that satisfies a condition or a default value if no such item is found.


Returns: NeoDictionaryItem<TKey, TValue>
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
Select

Projects each item of the NeoDictionary into a new form.


Returns: IEnumerable<NeoDictionaryItem<TKey, TValue>>
Parameters:
  • selector: Func<NeoDictionaryItem<TKey, TValue>, NeoDictionaryItem<TKey, TValue>>
IndexOf

Returns the index of the given NeoDictionaryItem.


Returns: int
Parameters:
  • selector: NeoDictionaryItem<TKey, TValue>
Remove

Removes the item with the given key.


Returns: void
Parameters:
  • key: TKey
RemoveAt

Removes the item at the given index.


Returns: void
Parameters:
  • index: int
Replace

Replaces the value for the given key if it exists.


Returns: void
Parameters:
  • key: TKey
  • value: TValue
HasKey

Checks if the NeoDictionary contains the given key.


Returns: bool
Parameters:
  • key: TKey
Clear

Clears all items from the NeoDictionary.


Returns: void
Sort

Sorts the NeoDictionary items using the given comparison.


Returns: void
Parameters:
  • comparison: Comparison<NeoDictionaryItem<TKey, TValue>>
Count

Returns the number of items in the NeoDictionary.


Returns: int
ForEach

Performs the given action on each item in the NeoDictionary.


Returns: void
Parameters:
  • action: Action<NeoDictionaryItem<TKey, TValue>>
ToList

Converts the NeoDictionary items to a List.


Returns: List<NeoDictionaryItem<TKey, TValue>>
Clone

Creates a shallow copy of the NeoDictionary.


Returns: NeoDictionary<TKey, TValue>
Reverse

Reverses the order of the items in the NeoDictionary.


Returns: void
Insert

Inserts an item at the given index.


Returns: void
Parameters:
  • index: int
  • key: TKey
  • value: TValue
InsertRange

Inserts a range of items starting from the given index.


Returns: void
Parameters:
  • index: int
  • values: IEnumerable<NeoDictionaryItem<TKey, TValue>>
RemoveRange

Removes a range of items starting from the given index.


Returns: void
Parameters:
  • index: int
  • count: int
RemoveAll

Removes all items matching the given predicate.


Returns: void
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
FindIndex

Finds the index of the first item matching the given predicate.


Returns: int
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
Find

Finds the first item matching the given predicate.


Returns: NeoDictionaryItem<TKey, TValue>
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
FindAll

Finds all items matching the given predicate.


Returns: IEnumerable<NeoDictionaryItem<TKey, TValue>>
Parameters:
  • predicate: Func<NeoDictionaryItem<TKey, TValue>, bool>
Merge

Merges another NeoDictionary into this one, ignoring duplicate keys.


Returns: void
Parameters:
  • other: NeoDictionary<TKey, TValue>
ToDictionarySafe

Converts the NeoDictionary to a standard Dictionary while safely handling duplicate keys by ignoring them.


Returns: Dictionary<TKey, TValue>

StringExtensions

OmegaLeo.HelperLib
Member Documentation
StringExtensions

Provides extension methods for the string data type.


Truncate

Truncates the string to a specified maximum number of characters, appending '...' if truncation occurs.


Returns: string
Parameters:
  • value: string
  • maxChars: int
Attribute Args:
  • value: The string to truncate.
  • maxChars: The maximum number of characters allowed before truncation.
Example:
var longString = "This is a very long string that needs to be truncated.";
var truncatedString = longString.Truncate(20); // truncatedString will be "This is a very long..."
IsNullOrEmpty

Checks if the string is null or empty.


Returns: bool
Parameters:
  • str: string
Attribute Args:
  • str: The string to check.
Example:
string myString = "";
bool isNullOrEmpty = myString.IsNullOrEmpty(); // isNullOrEmpty will be true
IsNotNullOrEmpty

Checks if the string is not null or empty.


Returns: bool
Parameters:
  • str: string
Attribute Args:
  • str: The string to check.
Example:
string myString = "Hello";
bool isNotNullOrEmpty = myString.IsNotNullOrEmpty(); // isNotNullOrEmpty will be true
AnyMatch

Checks if the string matches any of the provided search strings, ignoring case.


Returns: bool
Parameters:
  • str: string
  • search: string[]
Attribute Args:
  • str: The string to check.
  • search: An array of strings to match against.
Example:
string myString = "Hello";
bool matches = myString.AnyMatch("hi", "hello", "greetings"); // matches will be true
Reverse

Reverses the characters in the string.


Returns: string
Parameters:
  • str: string
Attribute Args:
  • str: The string to reverse.
Example:
string myString = "Hello";
string reversedString = myString.Reverse(); // reversedString will be "olleH"

Changelog

Version 1.2.0

January 28, 2026

OmegaLeo.HelperLib.Extensions

  • ArrayExtensions:
    • Fixed root namespace to OmegaLeo.HelperLib.Extensions.
  • FloatExtensions:
    • Fixed root namespace to OmegaLeo.HelperLib.Extensions.
  • IListExtensions:
    • Fixed root namespace to OmegaLeo.HelperLib.Extensions.
  • MathExtensions:
    • Fixed root namespace to OmegaLeo.HelperLib.Extensions.
  • StringExtensions:
    • Fixed root namespace to OmegaLeo.HelperLib.Extensions.

OmegaLeo.HelperLib.Helpers

  • BenchmarkUtility:
    • Fixed root namespace to OmegaLeo.HelperLib.Helpers.

OmegaLeo.HelperLib.Models

  • InstancedObject:
    • Fixed root namespace to OmegaLeo.HelperLib.Models.
  • NeoDictionary:
    • Fixed root namespace to OmegaLeo.HelperLib.Models.