diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-06 21:10:57 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-06 21:10:57 +0200 |
| commit | 36bde2234f457f4bb93caf6d1f2e47ddf895be39 (patch) | |
| tree | 5f566164a3f0cda4fc329151058354893263c5c6 /Software/Visual_Studio/Tango.Core | |
| parent | cc707ae8bd0100449e9e8fb68e09dae144421b54 (diff) | |
| download | Tango-36bde2234f457f4bb93caf6d1f2e47ddf895be39.tar.gz Tango-36bde2234f457f4bb93caf6d1f2e47ddf895be39.zip | |
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
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs | 17 |
1 files changed, 17 insertions, 0 deletions
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()); } + + /// <summary> + /// Orders the collection by natural alphanumeric string. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="source">The source.</param> + /// <param name="selector">The selector.</param> + /// <returns></returns> + public static IOrderedEnumerable<T> OrderByAlphaNumeric<T>(this IEnumerable<T> source, Func<T, string> selector) + { + int max = source + .SelectMany(i => Regex.Matches(selector(i), @"\d+").Cast<Match>().Select(m => (int?)m.Value.Length)) + .Max() ?? 0; + + return source.OrderBy(i => Regex.Replace(selector(i), @"\d+", m => m.Value.PadLeft(max, '0'))); + } } |
