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


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.


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.


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.


Stop

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


GetResults

Retrieves the list of recorded times for the given key.


ClearResults

Clears all recorded benchmark results.


GetAllResults

Retrieves all recorded benchmark results.


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.


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.


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.


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.


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.


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.


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.


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.


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


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.


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.


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.


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.


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.


TryGetValueFromIndex

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


Add

Adds a new NeoDictionaryItem to the NeoDictionary.


AddRange

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


AddRange

Adds a range of NeoDictionaryItems to the NeoDictionary.


Any

Checks if the NeoDictionary has any items.


Any

Checks if any item in the NeoDictionary satisfies a condition.


Where

Filters the NeoDictionary items based on a predicate.


FirstOrDefault

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


FirstOrDefault

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


LastOrDefault

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


LastOrDefault

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


Select

Projects each item of the NeoDictionary into a new form.


IndexOf

Returns the index of the given NeoDictionaryItem.


Remove

Removes the item with the given key.


RemoveAt

Removes the item at the given index.


Replace

Replaces the value for the given key if it exists.


HasKey

Checks if the NeoDictionary contains the given key.


Clear

Clears all items from the NeoDictionary.


Sort

Sorts the NeoDictionary items using the given comparison.


Count

Returns the number of items in the NeoDictionary.


ForEach

Performs the given action on each item in the NeoDictionary.


ToList

Converts the NeoDictionary items to a List.


Clone

Creates a shallow copy of the NeoDictionary.


Reverse

Reverses the order of the items in the NeoDictionary.


Insert

Inserts an item at the given index.


InsertRange

Inserts a range of items starting from the given index.


RemoveRange

Removes a range of items starting from the given index.


RemoveAll

Removes all items matching the given predicate.


FindIndex

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


Find

Finds the first item matching the given predicate.


FindAll

Finds all items matching the given predicate.


Merge

Merges another NeoDictionary into this one, ignoring duplicate keys.


ToDictionarySafe

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


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.


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.


Example:
string myString = "";
bool isNullOrEmpty = myString.IsNullOrEmpty(); // isNullOrEmpty will be true
IsNotNullOrEmpty

Checks if the string is not null or empty.


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.


Example:
string myString = "Hello";
bool matches = myString.AnyMatch("hi", "hello", "greetings"); // matches will be true
Reverse

Reverses the characters in the string.


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.