gt.Collections.OrderedList
0.2.0
dotnet add package gt.Collections.OrderedList --version 0.2.0
NuGet\Install-Package gt.Collections.OrderedList -Version 0.2.0
<PackageReference Include="gt.Collections.OrderedList" Version="0.2.0" />
<PackageVersion Include="gt.Collections.OrderedList" Version="0.2.0" />
<PackageReference Include="gt.Collections.OrderedList" />
paket add gt.Collections.OrderedList --version 0.2.0
#r "nuget: gt.Collections.OrderedList, 0.2.0"
#:package gt.Collections.OrderedList@0.2.0
#addin nuget:?package=gt.Collections.OrderedList&version=0.2.0
#tool nuget:?package=gt.Collections.OrderedList&version=0.2.0
gt.Collections.Ordered
Installation
Available on NuGet
Visual Studio:
PM> Install-Package gt.Collections.OrderedList
.NET Core CLI:
dotnet add package gt.Collections.OrderedList
Usage
usage with primitives
var list = OrderedCollection<int>.Create(n => n); // or new OrderedCollection<int, int>(n=>n)
list.Add(2);
list.Add(-1);
list.Add(3);
list.Add(0);
Console.WriteLine(string.Join(", ", list)); // -1, 0, 2, 3
usage with complex objects that throw notifications
var list = OrderedCollection<TestNotifyObj>.Create(n => n.Order); // collection uses bisect-right logic by default
var o1 = new TestNotifyObj(2);
var o2 = new TestNotifyObj(3);
var objectToChange = new TestNotifyObj(1);
list.Add(o1);
list.Add(o2);
list.Add(objectToChange);
Console.WriteLine(string.Join(", ", list)); // Id: 3, Order: 1; Id: 1, Order: 2; Id: 2, Order: 3
objectToChange.Order = 2;
Console.WriteLine(string.Join(", ", list)); // Id: 1, Order: 2, Id: 3, Order: 2, Id: 2, Order: 3
...
public class TestNotifyObj : INotifyPropertyChanged
{
private int _order;
private static int _lastId;
public TestNotifyObj()
{
Id = ++_lastId;
}
public TestNotifyObj(int order) : this()
{
Order = order;
}
public int Id { get; }
public int Order
{
get => _order;
set
{
if (value == _order) return;
_order = value;
OnPropertyChanged();
}
}
public override string ToString()
{
return $"Id: {Id}, Order: {Order}";
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
You also can use OrderedList instead of OrderedCollection.
Mode
You can change mode by passing sortMethod parameter to the constructor or static method Create of collection.
BisectRight mode (default value of sortMethod parameter)
If entries with same order are already present in collection, the insertion point will be after (to the right of) any existing entries.
new OrderedCollection<TestNotifyObj, int>(n=>n.Order, sortMethod: SortMethod.BisectRight);
BisectLeft mode
If entries with same order are already present in collection, the insertion point will be before (to the left of) any existing entries.
new OrderedCollection<TestNotifyObj, int>(n=>n.Order, sortMethod: SortMethod.BisectLeft);
Helpers
BinarySearchHelper - Binary search algorithm implementation logic for generic collection.
SortingHelper - Binary search algorithm with right and left insertion modes logic.
Contributing
Contributions are highly welcome. If you have found a bug or if you have a feature request, please report them at this repository issues section.
License
This project is licensed under the MIT license. See the LICENSE file for more info.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.