Hto3.CollectionHelpers 1.0.8

dotnet add package Hto3.CollectionHelpers --version 1.0.8                
NuGet\Install-Package Hto3.CollectionHelpers -Version 1.0.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hto3.CollectionHelpers" Version="1.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hto3.CollectionHelpers --version 1.0.8                
#r "nuget: Hto3.CollectionHelpers, 1.0.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hto3.CollectionHelpers as a Cake Addin
#addin nuget:?package=Hto3.CollectionHelpers&version=1.0.8

// Install Hto3.CollectionHelpers as a Cake Tool
#tool nuget:?package=Hto3.CollectionHelpers&version=1.0.8                

logo

Hto3.CollectionHelpers

License Hto3.CollectionHelpers Downloads Build Status codecov Codacy Badge

Features

A set of extension methods that can be used to facilitate the manipulation of collections solving common dev problems.

EmptyIfNull

If the collection is null then 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 of the item (like String.Format), and the string to use to separate the items. Similar experience like String.Join.

var collection = new List<Int32>();
collection.Add(1);
collection.Add(2);
collection.Add(3);

collection.Describe() == "1, 2, 3";

IsUnderCollectionChangedEvent

Check if the execution stack is within a CollectionChanged call 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

Build 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 condition defined by 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

Flatten a tree structure.

//To-do put an example

ReplaceAllBy

Replaces all items in an ObservableCollection with other items. It's the same as calling the <i>Clear()</i> method and then adding the new items (optmized performance).

//To-do put an example

AddRange

Add multiple items to a collection invoking the change event only one time, at the end.

//To-do put an example

AddRangeIfNotExists

Add multiple items to a collection without repeating if the item already exists.

//To-do put an example

Move

Moves a position item.

//To-do put an example

AddIfNotExists

Adds an item only if it does not 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 type of items 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 defined as the set of elements which are in one of the sets, but not in both.

//To-do put an example

ForEach

Performs immediately an action for each item in the collection.

//To-do put an example

ForEachSelect

Performs immediately an action for each item in the collection.

//To-do put an example

ToObservableCollection

Converts a generic collection into an observable collection (ObservableCollection).

//To-do put an example

Window

Makes a work window in a data collection.

//To-do put an example

TryUntilSuccess

Try something on each item of a collection. For more advanced needs, check https://www.nuget.org/packages/Polly/.

//To-do put an example

PickRandom

Pick a random item from the collection or the default item value if the sequence contains no elements.

//To-do put an example

PickRandomOrDefault

Pick a random item from the collection or the default item value if the sequence contains no elements.

//To-do put an example

Shuffle

Shuffle 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
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.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.

Version Downloads Last updated
1.0.8 176 1/7/2024
1.0.7 434 11/15/2021
1.0.6 350 6/14/2021
1.0.5 346 2/17/2021
1.0.4 477 1/21/2020
1.0.3 486 9/28/2019
1.0.2 519 9/21/2019
1.0.1 491 9/14/2019
1.0.0 537 6/23/2019