From 4919bb1161968c7ef01bc1dbed8da857c5937a6e Mon Sep 17 00:00:00 2001 From: James Vaughan Date: Thu, 13 Aug 2026 15:55:35 -0400 Subject: [PATCH 1/2] Add Span option for creating categories --- src/TMG-Framework/Data/Categories.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/TMG-Framework/Data/Categories.cs b/src/TMG-Framework/Data/Categories.cs index ceb3d23..ec4e7e3 100644 --- a/src/TMG-Framework/Data/Categories.cs +++ b/src/TMG-Framework/Data/Categories.cs @@ -66,6 +66,31 @@ public static bool CreateCategories(List elements, return true; } + /// + /// + /// + /// + /// + /// + public static bool CreateCategories(Span elements, + [NotNullWhen(true)] out Categories? categories, + [NotNullWhen(false)] ref string? error) + { + var list = new List(elements.ToArray()); + list.Sort(); + for (int i = 1; i < list.Count; i++) + { + if(list[i - 1] == list[i]) + { + error = $"Found a duplicate category {list[i]}!"; + categories = null; + return false; + } + } + categories = new Categories(list); + return true; + } + /// /// Create a SparseMap from a list of elements /// From e88f4db08ca2020dc9eb7ff4d96d48766697f01b Mon Sep 17 00:00:00 2001 From: James Vaughan Date: Thu, 13 Aug 2026 15:58:12 -0400 Subject: [PATCH 2/2] Added better commenting --- src/TMG-Framework/Data/Categories.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/TMG-Framework/Data/Categories.cs b/src/TMG-Framework/Data/Categories.cs index ec4e7e3..a5bf743 100644 --- a/src/TMG-Framework/Data/Categories.cs +++ b/src/TMG-Framework/Data/Categories.cs @@ -42,11 +42,11 @@ public sealed class Categories : IEnumerable private readonly List _elements; /// - /// + /// Create a Categories instance from a list of elements /// - /// - /// - /// + /// The list of elements to use, values will be sorted, any duplicates will return in failure. + /// The error message if creation fails + /// True if creation succeeds, false otherwise public static bool CreateCategories(List elements, [NotNullWhen(true)] out Categories? categories, [NotNullWhen(false)] ref string? error) @@ -66,12 +66,12 @@ public static bool CreateCategories(List elements, return true; } - /// - /// + /// + /// Create a Categories instance from a list of elements /// - /// - /// - /// + /// The list of elements to use, values will be sorted, any duplicates will return in failure. + /// The error message if creation fails + /// True if creation succeeds, false otherwise public static bool CreateCategories(Span elements, [NotNullWhen(true)] out Categories? categories, [NotNullWhen(false)] ref string? error) @@ -92,9 +92,9 @@ public static bool CreateCategories(Span elements, } /// - /// Create a SparseMap from a list of elements + /// Create a Categories instance from a list of elements /// - /// The sorted elements to use + /// The sorted list of elements to use private Categories(List elements) { if(elements == null)