From 36bde2234f457f4bb93caf6d1f2e47ddf895be39 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 6 Dec 2019 21:10:57 +0200 Subject: Added new PID and heaters to hw, diagnostics and tech. Implemented proper sorting on hw version and tech board. (DB CHANGE!) Related Work Items: #1595 --- .../ExtensionMethods/IEnumerableExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods') diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs index f4192a88b..68594d8ac 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Tango.Core; @@ -104,5 +105,21 @@ public static class IEnumerableExtensions { return source.GroupBy(property).Select(g => g.First()); } + + /// + /// Orders the collection by natural alphanumeric string. + /// + /// + /// The source. + /// The selector. + /// + public static IOrderedEnumerable OrderByAlphaNumeric(this IEnumerable source, Func selector) + { + int max = source + .SelectMany(i => Regex.Matches(selector(i), @"\d+").Cast().Select(m => (int?)m.Value.Length)) + .Max() ?? 0; + + return source.OrderBy(i => Regex.Replace(selector(i), @"\d+", m => m.Value.PadLeft(max, '0'))); + } } -- cgit v1.3.1