mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-23 23:40:47 +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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,7 @@
|
|||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
|
@ -82,36 +80,6 @@ namespace Utilities
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
public new KeyValuePairList<TKey, TValue> GetRange(int index, int count)
|
||||
{
|
||||
return new KeyValuePairList<TKey, TValue>(base.GetRange(index, count));
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
<Compile Include="Cryptography\CRC32.cs" />
|
||||
<Compile Include="Generics\BlockingQueue.cs" />
|
||||
<Compile Include="Generics\KeyValuePairList.cs" />
|
||||
<Compile Include="Generics\KeyValuePairList.Sort.cs" />
|
||||
<Compile Include="Generics\Map.cs" />
|
||||
<Compile Include="Generics\Reference.cs" />
|
||||
<Compile Include="Generics\SortedList.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue