WIP: Generate XML documentation from DocumentationAttribute for IDE IntelliSense #12
@@ -5,30 +5,19 @@ using OmegaLeo.HelperLib.Shared.Attributes;
|
|||||||
|
|
||||||
namespace OmegaLeo.HelperLib.Helpers
|
namespace OmegaLeo.HelperLib.Helpers
|
||||||
{
|
{
|
||||||
/// <summary>
|
[Documentation(nameof(BenchmarkUtility), "Utility class for benchmarking code execution time.", null, @"```csharp
|
||||||
/// Utility class for benchmarking code execution time.
|
|
||||||
/// </summary>
|
|
||||||
[Documentation(nameof(BenchmarkUtility), "Utility class for benchmarking code execution time.", null, @"```csharp
|
|
||||||
BenchmarkUtility.Start(""MyBenchmark"");
|
BenchmarkUtility.Start(""MyBenchmark"");
|
||||||
// Code to benchmark
|
// Code to benchmark
|
||||||
BenchmarkUtility.Stop(""MyBenchmark"");
|
BenchmarkUtility.Stop(""MyBenchmark"");
|
||||||
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
||||||
```")]
|
```")]
|
||||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Helpers.", "January 28, 2026")]
|
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Helpers.", "January 28, 2026")]
|
||||||
/// <summary>
|
|
||||||
/// Utility class for benchmarking code execution time.
|
|
||||||
/// </summary>
|
|
||||||
public class BenchmarkUtility
|
public class BenchmarkUtility
|
||||||
{
|
{
|
||||||
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
|
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
|
||||||
private static Dictionary<string, Stopwatch> _stopwatches = new Dictionary<string, Stopwatch>();
|
private static Dictionary<string, Stopwatch> _stopwatches = new Dictionary<string, Stopwatch>();
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("GetStopwatch", "Retrieves or creates a Stopwatch instance for the given key.", null, null)]
|
||||||
/// Retrieves or creates a Stopwatch instance for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key parameter</param>
|
|
||||||
/// <returns>The return value</returns>
|
|
||||||
[Documentation("GetStopwatch", "Retrieves or creates a Stopwatch instance for the given key.", null, null)]
|
|
||||||
private static Stopwatch GetStopwatch(string key)
|
private static Stopwatch GetStopwatch(string key)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch;
|
Stopwatch stopwatch;
|
||||||
@@ -42,12 +31,7 @@ var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
|||||||
return stopwatch;
|
return stopwatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("Record", "Records the execution time of the provided action and returns the elapsed time in milliseconds.", null, @"```csharp
|
||||||
/// Records the execution time of the provided action and returns the elapsed time in milliseconds.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="actionToRecord">The actionToRecord parameter</param>
|
|
||||||
/// <returns>The return value</returns>
|
|
||||||
[Documentation("Record", "Records the execution time of the provided action and returns the elapsed time in milliseconds.", null, @"```csharp
|
|
||||||
var time = BenchmarkUtility.Record(() =>
|
var time = BenchmarkUtility.Record(() =>
|
||||||
{
|
{
|
||||||
// Code to benchmark
|
// Code to benchmark
|
||||||
@@ -66,13 +50,7 @@ Console.WriteLine($""Elapsed time: {time} ms"");
|
|||||||
return stopwatch.ElapsedMilliseconds;
|
return stopwatch.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("RecordAndSaveToResults", "Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.", null, @"```csharp
|
||||||
/// Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key parameter</param>
|
|
||||||
/// <param name="actionToRecord">The actionToRecord parameter</param>
|
|
||||||
/// <returns>The return value</returns>
|
|
||||||
[Documentation("RecordAndSaveToResults", "Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.", null, @"```csharp
|
|
||||||
var time = BenchmarkUtility.RecordAndSaveToResults(""MyBenchmark"", () =>
|
var time = BenchmarkUtility.RecordAndSaveToResults(""MyBenchmark"", () =>
|
||||||
{
|
{
|
||||||
// Code to benchmark
|
// Code to benchmark
|
||||||
@@ -104,29 +82,13 @@ Console.WriteLine($""Average time: {averageTime} ms"");
|
|||||||
return stopwatch.ElapsedMilliseconds;
|
return stopwatch.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("Start", "Starts or restarts the stopwatch for the given key.", null, null)]
|
||||||
/// Starts or restarts the stopwatch for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key parameter</param>
|
|
||||||
[Documentation("Start", "Starts or restarts the stopwatch for the given key.", null, null)]
|
|
||||||
/// <summary>
|
|
||||||
/// Starts or restarts the stopwatch for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The benchmark identifier</param>
|
|
||||||
public static void Start(string key)
|
public static void Start(string key)
|
||||||
{
|
{
|
||||||
GetStopwatch(key).Restart();
|
GetStopwatch(key).Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("Stop", "Stops the stopwatch for the given key and records the elapsed time.", null, null)]
|
||||||
/// Stops the stopwatch for the given key and records the elapsed time.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key parameter</param>
|
|
||||||
[Documentation("Stop", "Stops the stopwatch for the given key and records the elapsed time.", null, null)]
|
|
||||||
/// <summary>
|
|
||||||
/// Stops the stopwatch for the given key and records the elapsed time.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The benchmark identifier</param>
|
|
||||||
public static void Stop(string key)
|
public static void Stop(string key)
|
||||||
{
|
{
|
||||||
if (!_benchmarks.ContainsKey(key))
|
if (!_benchmarks.ContainsKey(key))
|
||||||
@@ -138,36 +100,19 @@ Console.WriteLine($""Average time: {averageTime} ms"");
|
|||||||
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
|
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("GetResults", "Retrieves the list of recorded times for the given key.", null, null)]
|
||||||
/// Retrieves the list of recorded times for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key parameter</param>
|
|
||||||
/// <returns>The return value</returns>
|
|
||||||
[Documentation("GetResults", "Retrieves the list of recorded times for the given key.", null, null)]
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the list of recorded times for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The benchmark identifier</param>
|
|
||||||
/// <returns>List of recorded times in milliseconds</returns>
|
|
||||||
public static List<long> GetResults(string key)
|
public static List<long> GetResults(string key)
|
||||||
{
|
{
|
||||||
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
|
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("ClearResults", "Clears all recorded benchmark results.", null, null)]
|
||||||
/// Clears all recorded benchmark results.
|
|
||||||
/// </summary>
|
|
||||||
[Documentation("ClearResults", "Clears all recorded benchmark results.", null, null)]
|
|
||||||
public static void ClearResults()
|
public static void ClearResults()
|
||||||
{
|
{
|
||||||
_benchmarks.Clear();
|
_benchmarks.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Documentation("GetAllResults", "Retrieves all recorded benchmark results.", null, null)]
|
||||||
/// Retrieves all recorded benchmark results.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The return value</returns>
|
|
||||||
[Documentation("GetAllResults", "Retrieves all recorded benchmark results.", null, null)]
|
|
||||||
public static Dictionary<string, List<long>> GetAllResults()
|
public static Dictionary<string, List<long>> GetAllResults()
|
||||||
{
|
{
|
||||||
return new Dictionary<string, List<long>>(_benchmarks);
|
return new Dictionary<string, List<long>>(_benchmarks);
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ namespace OmegaLeo.HelperLib.Models
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
[Documentation("NeoDictionary", "Dictionary like class created to make it easier to display dictionaries in game engines like Unity")]
|
[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")]
|
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Models.", "January 28, 2026")]
|
||||||
/// <summary>
|
|
||||||
/// Dictionary like class created to make it easier to display dictionaries in game engines like Unity.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">The type of keys in the dictionary</typeparam>
|
|
||||||
/// <typeparam name="TValue">The type of values in the dictionary</typeparam>
|
|
||||||
public class NeoDictionary<TKey,TValue>
|
public class NeoDictionary<TKey,TValue>
|
||||||
{
|
{
|
||||||
public List<NeoDictionaryItem<TKey, TValue>> Items = new List<NeoDictionaryItem<TKey, TValue>>();
|
public List<NeoDictionaryItem<TKey, TValue>> Items = new List<NeoDictionaryItem<TKey, TValue>>();
|
||||||
@@ -28,12 +23,6 @@ namespace OmegaLeo.HelperLib.Models
|
|||||||
: new Dictionary<TKey, TValue>();
|
: new Dictionary<TKey, TValue>();
|
||||||
|
|
||||||
[Documentation("TryGetValue", "Tries to get the value from the NeoDictionary for the given key.")]
|
[Documentation("TryGetValue", "Tries to get the value from the NeoDictionary for the given key.")]
|
||||||
/// <summary>
|
|
||||||
/// Tries to get the value from the NeoDictionary for the given key.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key to search for</param>
|
|
||||||
/// <param name="value">The value associated with the key, if found</param>
|
|
||||||
/// <returns>True if the key was found, false otherwise</returns>
|
|
||||||
public bool TryGetValue(TKey key, out TValue value)
|
public bool TryGetValue(TKey key, out TValue value)
|
||||||
{
|
{
|
||||||
var item = Items.FirstOrDefault(x => x.Key.Equals(key));
|
var item = Items.FirstOrDefault(x => x.Key.Equals(key));
|
||||||
@@ -50,12 +39,6 @@ namespace OmegaLeo.HelperLib.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Documentation("TryGetValueFromIndex", "Tries to get the value from the NeoDictionary at the given index.")]
|
[Documentation("TryGetValueFromIndex", "Tries to get the value from the NeoDictionary at the given index.")]
|
||||||
/// <summary>
|
|
||||||
/// Tries to get the value from the NeoDictionary at the given index.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="index">The zero-based index of the element</param>
|
|
||||||
/// <param name="value">The value at the specified index, if found</param>
|
|
||||||
/// <returns>True if the index is valid, false otherwise</returns>
|
|
||||||
public bool TryGetValueFromIndex(int index, out TValue value)
|
public bool TryGetValueFromIndex(int index, out TValue value)
|
||||||
{
|
{
|
||||||
if (index < Items.Count)
|
if (index < Items.Count)
|
||||||
@@ -75,11 +58,6 @@ namespace OmegaLeo.HelperLib.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Documentation("Add", "Adds a new NeoDictionaryItem to the NeoDictionary.")]
|
[Documentation("Add", "Adds a new NeoDictionaryItem to the NeoDictionary.")]
|
||||||
/// <summary>
|
|
||||||
/// Adds a new NeoDictionaryItem to the NeoDictionary.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key of the element to add</param>
|
|
||||||
/// <param name="value">The value of the element to add</param>
|
|
||||||
public void Add(TKey key, TValue value)
|
public void Add(TKey key, TValue value)
|
||||||
{
|
{
|
||||||
Items.Add(new NeoDictionaryItem<TKey, TValue>(key, value));
|
Items.Add(new NeoDictionaryItem<TKey, TValue>(key, value));
|
||||||
|
|||||||
Reference in New Issue
Block a user