mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-02 22:11:50 +02:00
Utilities: KeyValuePairList: Moved Sort logic to partial class
This commit is contained in:
parent
7599670481
commit
349dcdd320
3 changed files with 45 additions and 32 deletions
44
Utilities/Generics/KeyValuePairList.Sort.cs
Normal file
44
Utilities/Generics/KeyValuePairList.Sort.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Copyright (C) 2012-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
*
|
||||
* You can redistribute this program and/or modify it under the terms of
|
||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public partial class KeyValuePairList<TKey, TValue>
|
||||
{
|
||||
new public void Sort()
|
||||
{
|
||||
this.Sort(Comparer<TKey>.Default);
|
||||
}
|
||||
|
||||
public void Sort(ListSortDirection sortDirection)
|
||||
{
|
||||
Sort(Comparer<TKey>.Default, sortDirection);
|
||||
}
|
||||
|
||||
public void Sort(IComparer<TKey> comparer, ListSortDirection sortDirection)
|
||||
{
|
||||
if (sortDirection == ListSortDirection.Ascending)
|
||||
{
|
||||
Sort(comparer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Sort(new ReverseComparer<TKey>(comparer));
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<TKey> comparer)
|
||||
{
|
||||
this.Sort(delegate(KeyValuePair<TKey, TValue> a, KeyValuePair<TKey, TValue> b)
|
||||
{
|
||||
return comparer.Compare(a.Key, b.Key);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue