Hto3.CollectionHelpers
1.0.9
dotnet add package Hto3.CollectionHelpers --version 1.0.9
NuGet\Install-Package Hto3.CollectionHelpers -Version 1.0.9
<PackageReference Include="Hto3.CollectionHelpers" Version="1.0.9" />
<PackageVersion Include="Hto3.CollectionHelpers" Version="1.0.9" />
<PackageReference Include="Hto3.CollectionHelpers" />
paket add Hto3.CollectionHelpers --version 1.0.9
#r "nuget: Hto3.CollectionHelpers, 1.0.9"
#:package Hto3.CollectionHelpers@1.0.9
#addin nuget:?package=Hto3.CollectionHelpers&version=1.0.9
#tool nuget:?package=Hto3.CollectionHelpers&version=1.0.9

Hto3.CollectionHelpers
Features
A set of extension methods that facilitate manipulation of collections and solve common development problems.
EmptyIfNull
If the collection is null, returns an empty collection.
IEnumerable<String> myCollection = null;
myCollection.EmptyIfNull().Count() == 0; //you won't get a NullReferenceException
Describe
Describes a list in a user-friendly string, allowing you to define the format for each item (like String.Format) and the string used to separate the items. Similar to String.Join.
var collection = new List<Int32>();
collection.Add(1);
collection.Add(2);
collection.Add(3);
collection.Describe() == "1, 2, 3";
IsUnderCollectionChangedEvent
Checks whether the execution stack is within a CollectionChanged event handler of an ObservableCollection.
var observableCollection = new ObservableCollection<String>();
observableCollection.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
{
var onEvent = observableCollection.IsUnderCollectionChangedEvent();
if (onEvent)
{
Console.WriteLine("We are inside a collection changed event!");
}
});
observableCollection.Add("first");
BuildCollectionFromString
Builds a typed list from a delimited string.
var delimitedString = "banana;apple;juice;lemon";
var result = delimitedString.BuildCollectionFromString<String>(";");
result.ElementAt(0) == "banana";
result.ElementAt(1) == "apple";
result.ElementAt(2) == "juice";
result.ElementAt(3) == "lemon";
Or dealing with cultural content:
var delimitedString = "30/07/2019;01/12/2020;26/02/2021";
var result = delimitedString.BuildCollectionFromString<DateTime>(";", new System.Globalization.CultureInfo("pt-BR"));
result.ElementAt(0) == new DateTime(2019, 7, 30);
result.ElementAt(1) == new DateTime(2020, 12, 1);
result.ElementAt(2) == new DateTime(2021, 2, 26);
RemoveAll
Removes all elements that satisfy the specified predicate.
var collection = new ObservableCollection<Int32>();
collection.Add(1);
collection.Add(2);
collection.Add(55);
collection.Add(100);
collection.RemoveAll(i => i > 10);
collection.Count == 2;
collection[0] == 1;
collection[1] == 2;
ReplaceItem
Replaces an item in an ObservableCollection.
var collection = new ObservableCollection<String>();
collection.Add("banana");
collection.Add("apple");
collection.Add("pinapple");
collection.ReplaceItem("apple", "strawberry");
collection.Count == 3;
collection[0] == "banana";
collection[1] == "strawberry";
collection[2] == "pinapple";
FlatTree
Flattens a tree structure.
//To-do put an example
ReplaceAllBy
Replaces all items in an ObservableCollection with other items. It's equivalent to calling <i>Clear()</i> and then adding the new items (optimized for performance).
//To-do put an example
AddRange
Adds multiple items to a collection, invoking the change event only once at the end.
//To-do put an example
AddRangeIfNotExists
Adds multiple items to a collection without adding duplicates if an item already exists.
//To-do put an example
Move
Moves an item to a different position.
//To-do put an example
AddIfNotExists
Adds an item only if it does not already exist in the collection.
//To-do put an example
RemoveIfExists
Removes an item only if it exists in the collection.
//To-do put an example
GetItemType
Gets the item type in a homogeneous collection.
//To-do put an example
SymmetricDifference
Gets the symmetric difference of two sets using an equality comparer. The symmetric difference is the set of elements that are in one of the sets but not in both.
//To-do put an example
ForEach
Immediately performs an action for each item in the collection.
//To-do put an example
ForEachSelect
Immediately performs an action for each item in the collection.
//To-do put an example
ToObservableCollection
Converts a generic collection into an ObservableCollection.
//To-do put an example
Window
Creates a sliding window over a collection.
//To-do put an example
TryUntilSuccess
Attempts an operation on each item of a collection until it succeeds. For advanced retry policies, see https://www.nuget.org/packages/Polly/.
//To-do put an example
PickRandom
Picks a random item from the collection or the default value if the sequence contains no elements.
//To-do put an example
PickRandomOrDefault
Picks a random item from the collection or the default value if the sequence contains no elements.
//To-do put an example
Shuffle
Shuffles the collection.
//To-do put an example
Run
Force one complete evaluation of an IEnumerable collection. Subsequent evaluation can occur after use this method, in another words, the collection will continue to be IEnumerable.
//To-do put an example
IsNullOrEmpty
Determines whether the specified sequence is null or contains no elements.
//To-do put an example
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. |
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. 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. |
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.