Migrated Documentation library from NetFlow.DocumentationHelper.Library
This commit is contained in:
Regular → Executable
Regular → Executable
+3
-2
@@ -1,8 +1,9 @@
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation("Array Extensions", "Set of extension methods to help with Arrays.")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class ArrayExtensions
|
||||
{
|
||||
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
|
||||
|
||||
Regular → Executable
+26
-1
@@ -1,14 +1,39 @@
|
||||
using System;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation(nameof(FloatExtensions), "Provides extension methods for the float data type.", null,
|
||||
"")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class FloatExtensions
|
||||
{
|
||||
[Documentation(nameof(Round), "Rounds a float value to the specified number of decimal places.",
|
||||
new[]
|
||||
{
|
||||
"value: The float value to round.",
|
||||
"digits: The number of decimal places to round to. Default is 2."
|
||||
},
|
||||
@"```cs
|
||||
var originalValue = 3.14159f;
|
||||
var roundedValue = originalValue.Round(2); // roundedValue will be 3.14
|
||||
```
|
||||
")]
|
||||
public static float Round(this float value, int digits = 2)
|
||||
{
|
||||
return MathF.Round(value, digits);
|
||||
}
|
||||
|
||||
[Documentation(nameof(RoundToInt), "Rounds a float value to the nearest integer and returns it as an int.",
|
||||
new[]
|
||||
{
|
||||
"value: The float value to round.",
|
||||
},
|
||||
@"```cs
|
||||
var originalValue = 3.14159f;
|
||||
var roundedValue = originalValue.RoundToInt(); // roundedValue will be 3
|
||||
```
|
||||
")]
|
||||
public static int RoundToInt(this float value)
|
||||
{
|
||||
return (int)value.Round(0);
|
||||
|
||||
Regular → Executable
+90
-15
@@ -2,9 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation(nameof(IListExtensions),
|
||||
"Extension methods for IList<T> to provide additional functionalities such as swapping, replacing, random selection, and shuffling.",
|
||||
null,
|
||||
"")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class IListExtensions
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,6 +21,19 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="indexB"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns>List with swapped elements</returns>
|
||||
[Documentation(nameof(Swap),
|
||||
"Swaps the elements at the specified indices in the list.",
|
||||
new[]
|
||||
{
|
||||
"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."
|
||||
},
|
||||
@"```cs
|
||||
var myList = new List<int> { 1, 2, 3, 4 };
|
||||
myList.Swap(0, 2); // myList is now { 3, 2, 1, 4 }
|
||||
```
|
||||
")]
|
||||
public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB)
|
||||
{
|
||||
(list[indexA], list[indexB]) = (list[indexB], list[indexA]);
|
||||
@@ -29,6 +48,19 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="itemB"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns>List with swapped elements</returns>
|
||||
[Documentation(nameof(Swap),
|
||||
"Swaps the elements at the specified indices in the list.",
|
||||
new[]
|
||||
{
|
||||
"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."
|
||||
},
|
||||
@"```cs
|
||||
var myList = new List<int> { 1, 2, 3, 4 };
|
||||
myList.Swap(0, 2); // myList is now { 3, 2, 1, 4 }
|
||||
```
|
||||
")]
|
||||
public static IList<T> Swap<T>(this IList<T> list, T itemA, T itemB)
|
||||
{
|
||||
return list.Swap(list.IndexOf(itemA), list.IndexOf(itemB));
|
||||
@@ -42,6 +74,18 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="valueToReplace"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Replace),
|
||||
"Replaces the first occurrence of a specified value in the list with a new value.",
|
||||
new[]
|
||||
{
|
||||
"list: The list in which to replace an element.",
|
||||
"originalValue: The value to be replaced.",
|
||||
"valueToReplace: The new value to insert."
|
||||
},
|
||||
@"```cs
|
||||
var myList = new List<int> { 1, 2, 3, 4 };
|
||||
myList.Replace(2, 5); // myList is now { 1, 5, 3, 4 }
|
||||
```")]
|
||||
public static IList<T> Replace<T>(this IList<T> list, T originalValue, T valueToReplace)
|
||||
{
|
||||
var index = list.IndexOf(originalValue);
|
||||
@@ -60,6 +104,16 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="list"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Random),
|
||||
"Selects a random element from the list.",
|
||||
new[]
|
||||
{
|
||||
"list: The list from which to select a random element."
|
||||
},
|
||||
@"```cs
|
||||
var myList = new List<int> { 1, 2, 3, 4 };
|
||||
var randomElement = myList.Random(); // randomElement could be any of 1, 2, 3, or 4
|
||||
```")]
|
||||
public static T Random<T>(this IList<T> list)
|
||||
{
|
||||
if (list.Count == 0) return default;
|
||||
@@ -85,6 +139,17 @@ namespace GameDevLibrary.Extensions
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
[Documentation(nameof(Random),
|
||||
"Selects a specified number of unique random elements from the list.",
|
||||
new[]
|
||||
{
|
||||
"list: The list from which to select random elements.",
|
||||
"count: The number of unique random elements to select."
|
||||
},
|
||||
@"```cs
|
||||
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
|
||||
```")]
|
||||
public static List<T> Random<T>(this IList<T> list, int count = 1)
|
||||
{
|
||||
if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
@@ -99,21 +164,19 @@ namespace GameDevLibrary.Extensions
|
||||
return values;
|
||||
}
|
||||
|
||||
/*public static IEnumerable<TSource> DistinctBy<TSource, TKey>
|
||||
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
HashSet<TKey> seenKeys = new HashSet<TKey>();
|
||||
foreach (TSource element in source)
|
||||
{
|
||||
if (seenKeys.Add(keySelector(element)))
|
||||
{
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
|
||||
[Documentation("Next<T>", @"Method to obtain the next object in the list by passing the current index.",
|
||||
new []
|
||||
{
|
||||
"CurrentIndex - The index we're currently on inside the list passed as reference so we can automatically assign to it the next index"
|
||||
},
|
||||
@"```cs
|
||||
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
|
||||
```
|
||||
")]
|
||||
public static T Next<T>(this List<T> array, ref int currentIndex)
|
||||
{
|
||||
return array[currentIndex++ % array.Count];
|
||||
@@ -125,6 +188,18 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[Documentation("Shuffle<T>",
|
||||
@"Shuffles the elements of the list in place using a cryptographic random number generator.
|
||||
|
||||
Code obtained from https://stackoverflow.com/a/1262619",
|
||||
new[]
|
||||
{
|
||||
"list: The list to be shuffled."
|
||||
},
|
||||
@"```cs
|
||||
var myList = new List<int> { 1, 2, 3, 4 };
|
||||
myList.Shuffle(); // myList could now be { 3, 1, 4, 2 } (example output)
|
||||
```")]
|
||||
public static IList<T> Shuffle<T>(this IList<T> list)
|
||||
{
|
||||
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
||||
|
||||
Regular → Executable
+31
-1
@@ -1,8 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation("MathExtensions", "Provides extension methods for mathematical operations.")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class MathExtensions
|
||||
{
|
||||
/// <summary>
|
||||
@@ -10,6 +13,15 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(AverageWithNullValidation),
|
||||
"Calculates the average of a list of integers, returning 0 if the list is empty.",
|
||||
new[] { "list: The list of integers to calculate the average from." },
|
||||
@"```csharp
|
||||
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
|
||||
```")]
|
||||
public static int AverageWithNullValidation(this IEnumerable<int> list)
|
||||
{
|
||||
return list.Any() ? (int)list.Average() : 0;
|
||||
@@ -20,6 +32,15 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(AverageWithNullValidation),
|
||||
"Calculates the average of a list of doubles, returning 0.0 if the list is empty.",
|
||||
new[] { "list: The list of doubles to calculate the average from." },
|
||||
@"```csharp
|
||||
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
|
||||
```")]
|
||||
public static double AverageWithNullValidation(this IEnumerable<double> list)
|
||||
{
|
||||
return list.Any() ? list.Average() : 0.0;
|
||||
@@ -30,6 +51,15 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(AverageWithNullValidation),
|
||||
"Calculates the average of a list of floats, returning 0.0f if the list is empty.",
|
||||
new[] { "list: The list of floats to calculate the average from." },
|
||||
@"```csharp
|
||||
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
|
||||
```")]
|
||||
public static float AverageWithNullValidation(this IEnumerable<float> list)
|
||||
{
|
||||
return list.Any() ? list.Average() : 0.0f;
|
||||
|
||||
Regular → Executable
+48
-1
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation(nameof(StringExtensions), "Provides extension methods for the string data type.", null,
|
||||
"")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
@@ -10,6 +14,17 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="value"></param>
|
||||
/// <param name="maxChars"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Truncate),
|
||||
"Truncates the string to a specified maximum number of characters, appending '...' if truncation occurs.",
|
||||
new[]
|
||||
{
|
||||
"value: The string to truncate.",
|
||||
"maxChars: The maximum number of characters allowed before truncation."
|
||||
},
|
||||
@"```cs
|
||||
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...""
|
||||
```")]
|
||||
public static string Truncate(this string value, int maxChars)
|
||||
{
|
||||
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
|
||||
@@ -20,6 +35,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(IsNullOrEmpty),
|
||||
"Checks if the string is null or empty.",
|
||||
new[] { "str: The string to check." },
|
||||
@"```cs
|
||||
string myString = """";
|
||||
bool isNullOrEmpty = myString.IsNullOrEmpty(); // isNullOrEmpty will be true
|
||||
```")]
|
||||
public static bool IsNullOrEmpty(this string str)
|
||||
{
|
||||
return String.IsNullOrEmpty(str);
|
||||
@@ -30,6 +52,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(IsNotNullOrEmpty),
|
||||
"Checks if the string is not null or empty.",
|
||||
new[] { "str: The string to check." },
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
bool isNotNullOrEmpty = myString.IsNotNullOrEmpty(); // isNotNullOrEmpty will be true
|
||||
```")]
|
||||
public static bool IsNotNullOrEmpty(this string str)
|
||||
{
|
||||
return !str.IsNullOrEmpty();
|
||||
@@ -41,6 +70,17 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="str"></param>
|
||||
/// <param name="search"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(AnyMatch),
|
||||
"Checks if the string matches any of the provided search strings, ignoring case.",
|
||||
new[]
|
||||
{
|
||||
"str: The string to check.",
|
||||
"search: An array of strings to match against."
|
||||
},
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
bool matches = myString.AnyMatch(""hi"", ""hello"", ""greetings""); // matches will be true
|
||||
```")]
|
||||
public static bool AnyMatch(this string str, params string[] search)
|
||||
{
|
||||
foreach (string s in search)
|
||||
@@ -59,6 +99,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Reverse),
|
||||
"Reverses the characters in the string.",
|
||||
new[] { "str: The string to reverse." },
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
string reversedString = myString.Reverse(); // reversedString will be ""olleH""
|
||||
```")]
|
||||
public static string Reverse(this string str)
|
||||
{
|
||||
char[] charArray = str.ToCharArray();
|
||||
|
||||
Regular → Executable
+3
-2
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Helpers
|
||||
namespace OmegaLeo.HelperLib.Helpers
|
||||
{
|
||||
[Documentation(nameof(BenchmarkUtility), "Utility class for benchmarking code execution time.", null, @"```csharp
|
||||
BenchmarkUtility.Start(""MyBenchmark"");
|
||||
@@ -11,6 +11,7 @@ BenchmarkUtility.Start(""MyBenchmark"");
|
||||
BenchmarkUtility.Stop(""MyBenchmark"");
|
||||
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
||||
```")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Helpers.", "January 28, 2026")]
|
||||
public class BenchmarkUtility
|
||||
{
|
||||
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
|
||||
|
||||
Regular → Executable
Regular → Executable
+11
-1
@@ -1,7 +1,17 @@
|
||||
using System;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Models
|
||||
namespace OmegaLeo.HelperLib.Models
|
||||
{
|
||||
[Serializable]
|
||||
[Documentation("InstancedObject<T> Class", "A generic base class that ensures only one instance of a derived class exists at any time.", new string[] { "T: The type of the derived class." },
|
||||
@"```cs
|
||||
public class MySingleton : InstancedObject<MySingleton>
|
||||
{
|
||||
// Your class implementation here
|
||||
}
|
||||
```")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Models.", "January 28, 2026")]
|
||||
public abstract class InstancedObject<T> where T : class
|
||||
{
|
||||
public static T Instance { get; private set; }
|
||||
|
||||
Regular → Executable
+3
-2
@@ -2,13 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Models
|
||||
namespace OmegaLeo.HelperLib.Models
|
||||
{
|
||||
// Inspiration: https://www.youtube.com/watch?v=x-ejym1WdjE
|
||||
[Serializable]
|
||||
[Documentation("NeoDictionary", "Dictionary like class created to make it easier to display dictionaries in game engines like Unity")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Models.", "January 28, 2026")]
|
||||
public class NeoDictionary<TKey,TValue>
|
||||
{
|
||||
public List<NeoDictionaryItem<TKey, TValue>> Items = new List<NeoDictionaryItem<TKey, TValue>>();
|
||||
|
||||
Regular → Executable
+8
-5
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>GameDevLibrary</RootNamespace>
|
||||
<RootNamespace>OmegaLeo.HelperLib</RootNamespace>
|
||||
<Version>0.0.2</Version>
|
||||
<Title>Omega Leo's Helper Library</Title>
|
||||
<Authors>Nuno "Omega Leo" Diogo</Authors>
|
||||
@@ -14,16 +14,19 @@
|
||||
<PackageLicenseExpression>AGPL-3.0-only</PackageLicenseExpression>
|
||||
<PackageTags>csharp;dotnet;utility;helper;benchmark</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\"/>
|
||||
<None Include="CHANGELOG.md" Pack="true" PackagePath="\"/>
|
||||
<None Include="LICENSE.md" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Changelog\OmegaLeo.HelperLib.Changelog.csproj" />
|
||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Documentation\OmegaLeo.HelperLib.Documentation.csproj" />
|
||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Shared\OmegaLeo.HelperLib.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user