AlastairLundy.Extensions.Collections 6.0.0

Prefix Reserved
dotnet add package AlastairLundy.Extensions.Collections --version 6.0.0                
NuGet\Install-Package AlastairLundy.Extensions.Collections -Version 6.0.0                
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="AlastairLundy.Extensions.Collections" Version="6.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AlastairLundy.Extensions.Collections --version 6.0.0                
#r "nuget: AlastairLundy.Extensions.Collections, 6.0.0"                
#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 AlastairLundy.Extensions.Collections as a Cake Addin
#addin nuget:?package=AlastairLundy.Extensions.Collections&version=6.0.0

// Install AlastairLundy.Extensions.Collections as a Cake Tool
#tool nuget:?package=AlastairLundy.Extensions.Collections&version=6.0.0                

CollectionExtensions

Extensions to C# IEnumerables, ICollections, and more to improve them.

This readme refers to the AlastairLundy.Extensions.Collections project and nuget package as CollectionExtensions for the sake of brevity.

NuGet NuGet

Table of Contents

Features

  • IDictionary AddRange extensions
  • HashMap types - Provides a Java like HashMap in .NET that uses a C# Dictionary under the hood.

How to install and use Collection Extensions

Collections Extensions can be installed via the .NET SDK CLI, Nuget via your IDE or code editor's package interface, or via the Nuget website.

Package Name Nuget Link .NET SDK CLI command
AlastairLundy.Extensions.Collections AlastairLundy.Extensions.Collections Nuget dotnet add package AlastairLundy.Extensions.Collections

Compatibility

Collections Extensions is compatible with the following .NET versions and Target Framework Monikers (TFMs).

Collections Extensions Version series .NET Targets supported
>= 6.0.0 .NET Standard 2.0, .NET Standard 2.1, .NET 8, and .NET 9
>= 5.4.0 && < 6.0.0 .NET Standard 2.0, .NET Standard 2.1, and .NET 8
< 5.4.0 .NET 8

Examples

Extension Methods

Dictionary Extensions
AddRange

Sometimes it may be desirable to initialize a dictionary with or without values AND then later add a dictionary or an IEnumerable of KeyValuePair objects tot the existing dictionary.

The IDictionary AddRange extension methods simplify this.

using System.Collections.Generic;

using AlastairLundy.Extensions.Collections.Generic;
    
    //Class names and other code ommitted.

// Initialize a dictionary here.
Dictionary<string, string> output = new Dictionary<string, string>();

List<KeyValuePair<string, string>> keyValuePairList = new List<KeyValuePair<string, string>>();
keyValuePairList.Add(new KeyValuePair("drums", "Your ears will hate you later."));
keyValuePairList.Add(new KeyValuePair("bass_guitar", "For when you're all about that bass."));
keyValuePairList.Add(new KeyValuePair("grand_piano", "A luxurious Grand Piano that probably costs a fortune"));

//Later on we can add an IEnumerable of KeyValuePair objects or even another dictionary.
output.AddRange(keyValuePairList);

How to Build CollectionExtensions's code

Requirements

CollectionExtensions requires the latest .NET release SDK to be installed to target all supported TFM (Target Framework Moniker) build targets.

Currently, the required .NET SDK is .NET 9.

The current build targets include:

  • .NET 8
  • .NET 9
  • .NET Standard 2.0
  • .NET Standard 2.1

Any version of the .NET 9 SDK can be used, but using the latest version is preferred.

Versioning new releases

CollectionExtensions aims to follow Semantic versioning with [Major].[Minor].[Build] for most circumstances and an optional .[Revision] when only a configuration change is made, or a new build of a preview release is made.

Pre-releases

Pre-release versions should have a suffix of -alpha, -beta, -rc, or -preview followed by a . and what pre-release version number they are. The number should be incremented by 1 after each release unless it only contains a configuration change, or another packaging, or build change. An example pre-release version may look like 1.1.0-alpha.2 , this version string would indicate it is the 2nd alpha pre-release version of 1.1.0 .

Stable Releases

Stable versions should follow semantic versioning and should only increment the Revision number if a release only contains configuration or build packaging changes, with no change in functionality, features, or even bug or security fixes.

Releases that only implement bug fixes should see the Build version incremented.

Releases that add new non-breaking changes should increment the Minor version. Minor breaking changes may be permitted in Minor version releases where doing so is necessary to maintain compatibility with an existing supported platform, or an existing piece of code that requires a breaking change to continue to function as intended.

Releases that add major breaking changes or significantly affect the API should increment the Major version. Major version releases should not be released with excessive frequency and should be released when there is a genuine need for the API to change significantly for the improvement of the project.

Building for Testing

You can build for testing by building the project within your IDE or VS Code, or manually by entering the following command: dotnet build -c Debug.

If you encounter any bugs or issues, try running the tests project and setting breakpoints in the affected code where appropriate. Failing that, please report the issue if one doesn't already exist for the bug(s).

Building for Release

Before building a release build, ensure you apply the relevant changes to the AlastairLundy.Extensions.Collections.csproj file:

  • Update the Package Version variable
  • Update the project file's Changelog

You should ensure the project builds under debug settings before producing a release build.

Producing Release Builds

To manually build for release, enter dotnet build -c Release /p:ContinuousIntegrationBuild=true for a release with SourceLink enabled or just dotnet build -c Release for a build without sourcelink.

Builds should generally always include Source Link and symbol packages if intended for wider distribution.

How to Contribute to CollectionExtensions

Thank you in advance for considering contributing to CollectionExtensions.

Please see the CONTRIBUTING.md file for code and localization contributions.

If you want to file a bug report or suggest a potential feature to add, please check out the GitHub issues page to see if a similar or identical issue is already open. If there is not already a relevant issue filed, please file one here and follow the respective guidance from the appropriate issue template.

Thanks.

CollectionExtensions's Roadmap

CollectionExtensions aims to make working with Generic Collections and IEnumerables in C# easier.

All stable releases must be stable and should not contain regressions.

Future updates should aim focus on one or more of the following:

  • Adding extension methods that improve ease of use
  • Adding new interfaces or classes that add useful Collections/IEnumerables related features that aren't an exact copy of an existing feature in .NET .
  • Enhancing existing extension methods, classes, or interfaces.

License

CollectionExtensions is licensed under the MIT license.

If you use CollectionExtensions in your project please make an exact copy of the contents of CollectionExtensions's LICENSE.txt file available either in your third party licenses txt file or as a separate txt file.

Acknowledgements

Projects

This project would like to thank the following projects for their work:

  • Polyfill for simplifying .NET Standard 2.0 & 2.1 support

For more information, please see the THIRD_PARTY_NOTICES file.

Product 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 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. 
.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AlastairLundy.Extensions.Collections:

Package Downloads
AlastairLundy.Extensions.Processes

ProcessExtensions adds much needed abstractions and extensions to Processes and Process Running, to make it easier and safer. ProcessExtensions started as part of CliRunner but is now a separate package, helping other projects besides CliRunner to run processes easily and safely.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0 193 2/18/2025
5.6.0 92 12/30/2024
5.5.0 99 11/29/2024
5.4.1 91 11/23/2024
5.4.0 140 10/14/2024
5.3.0 144 9/14/2024
5.2.1 126 9/14/2024
5.1.0 151 8/24/2024
5.0.0 148 7/8/2024

## Changes from 5.6.0

### Added

* add more xml doc comments in [`7415b0c`](https://github.com/alastairlundy/CollectionExtensions/commit/7415b0cd6aca14db8f707ce9ed25ae776d8e17b8)
* add unit testing project in [`01a4c0a`](https://github.com/alastairlundy/CollectionExtensions/commit/01a4c0abceae22c1b7fc10711d9b6c1c46a13a1d)
* add GetValueOrDefault method in [`0220e91`](https://github.com/alastairlundy/CollectionExtensions/commit/0220e91d71d3122ba79cf9a797aa69c990c8c782)

### Changed

* update ReadOnlyHashMap code and xml doc comments in [`4d184f8`](https://github.com/alastairlundy/CollectionExtensions/commit/4d184f8c3b9af7311fab92718c9cbd86b15389b5)
* re-add HashMaps in [`6841765`](https://github.com/alastairlundy/CollectionExtensions/commit/68417657aab4935f011440dd59864ddd095e56e3)
* simplify Dictionary GetValueOrDefault code in [`70089ce`](https://github.com/alastairlundy/CollectionExtensions/commit/70089cee95d34d474c0ced1fefb901b9fff2d076)
* prepare to add HashMaps back in [`aaa9811`](https://github.com/alastairlundy/CollectionExtensions/commit/aaa98112e461efd079957b83658d2792bf054aa1)
* Update AlastairLundy.Extensions.Collections.csproj in [`235b66e`](https://github.com/alastairlundy/CollectionExtensions/commit/235b66eaa0965826b081193cd57a7f4cd32c66e8)
* clean up project file in [`bdf117a`](https://github.com/alastairlundy/CollectionExtensions/commit/bdf117a67991456d644fb1a6749f9ae222d795f7)
* Update issue templates in [`f908700`](https://github.com/alastairlundy/CollectionExtensions/commit/f908700b6013ef4a632c8159acd4660e6512ec37)
* cleanup ContainsSeparator extensions in [`1c7e3ce`](https://github.com/alastairlundy/CollectionExtensions/commit/1c7e3ce7e42ff3e15c4c04e356b55231e1b8d9b8)
* Update ToStringEnumerablesExtensions.cs in [`3ed684d`](https://github.com/alastairlundy/CollectionExtensions/commit/3ed684d8868718ce6d4f43092243d95e94921595)
* set language version in [`a3cc3bf`](https://github.com/alastairlundy/CollectionExtensions/commit/a3cc3bf3e1dde8af8b5176de2ee960f19e9fc035)
* clean up code in [`331189f`](https://github.com/alastairlundy/CollectionExtensions/commit/331189f66325b528ad30bb9a2e70937d10adef6f)
* update test dependencies in [`5b5fa4e`](https://github.com/alastairlundy/CollectionExtensions/commit/5b5fa4e84127de5e6199c25998459c4c6cfed3d8)
* rename files in [`a5856a6`](https://github.com/alastairlundy/CollectionExtensions/commit/a5856a66b423246b3fedc4671d3af6ecc86687d3)
* enhance robustness of ToStringEnumerable check in [`63fcb05`](https://github.com/alastairlundy/CollectionExtensions/commit/63fcb05fba486851fc37c7c6ee1103d4abc9b26b)
* Update ToStringEnumerablesExtensions.cs in [`89a0b1d`](https://github.com/alastairlundy/CollectionExtensions/commit/89a0b1d36c556ced80853bed547192e6588f24b3)
* simplify toString method check in [`d6d6506`](https://github.com/alastairlundy/CollectionExtensions/commit/d6d65061015749236525395c4535347151aed26c)
* clarify exception message in [`bdd2e6a`](https://github.com/alastairlundy/CollectionExtensions/commit/bdd2e6ac17805e00faf5f62b17a461da71b44264)
* optimize performance in [`88dfe09`](https://github.com/alastairlundy/CollectionExtensions/commit/88dfe09698578114786b17fc46a4486cf719117d)
* adjust namespaces in [`d7b1c74`](https://github.com/alastairlundy/CollectionExtensions/commit/d7b1c749273f93e0cdffc98d9f46269187e10b4b)
* Update RemoveExtensions.cs in [`34f5566`](https://github.com/alastairlundy/CollectionExtensions/commit/34f55660f491bc2292fceeb7fa8b2100e6c08036)
* change return type to IEnumerable in [`8484bae`](https://github.com/alastairlundy/CollectionExtensions/commit/8484baefc6156cadf6f662ca0f903b917b2125a4)
* rename method in [`a8690f4`](https://github.com/alastairlundy/CollectionExtensions/commit/a8690f44a374c74351e20e9ee690b9bf9acb5a88)
* rename file in [`80250fe`](https://github.com/alastairlundy/CollectionExtensions/commit/80250fe2c1fa06119cd51d6b413aeb437f1fd3cc)
* rename methods to TryGetIndexesOf from TryIndexesof in [`63a0bd5`](https://github.com/alastairlundy/CollectionExtensions/commit/63a0bd50097ef735049e2780b8e7c494ce57003a)
* rename extension method in [`c6224a1`](https://github.com/alastairlundy/CollectionExtensions/commit/c6224a1166c2e6c03ce179bb781b8f1733f12bed)
* better handle string usage of generic ToString enumerable extension method in [`8455d81`](https://github.com/alastairlundy/CollectionExtensions/commit/8455d81925ecbc1287ecd36a801dced059b2a04e)
* separate generic and non generic ICollection index extensions in [`a8558b8`](https://github.com/alastairlundy/CollectionExtensions/commit/a8558b821718272b467558ee4cf1d8b299342c5e)
* move to non Generic namespace in [`c1ac346`](https://github.com/alastairlundy/CollectionExtensions/commit/c1ac346e309ca459ac61e3ad4f7d6204d01ab080)
* move Dictionary files and adjust namespaces in [`cedcdc6`](https://github.com/alastairlundy/CollectionExtensions/commit/cedcdc64fc60cd4f00b922cc304f782ac33b2147)
* clarify TKey constraint in [`df9d6b4`](https://github.com/alastairlundy/CollectionExtensions/commit/df9d6b4005a567de34d86d546bd88be56638e863)
* clarify language version in [`975d571`](https://github.com/alastairlundy/CollectionExtensions/commit/975d5716f4f1d2dbc42eda1baf355509648cc953)
* update in [`b4981c9`](https://github.com/alastairlundy/CollectionExtensions/commit/b4981c9da567646cae578e97cf92ef695a4b787c)
* simplify and improve performance of IEnumerable Remove extensions in [`efc8eb5`](https://github.com/alastairlundy/CollectionExtensions/commit/efc8eb5f14d7d737852b7e78c1305b48701f4311)
* Update AlastairLundy.Extensions.Collections.csproj in [`4840c10`](https://github.com/alastairlundy/CollectionExtensions/commit/4840c10f828af37839420d3069d3af631d6a7370)
* Update AlastairLundy.Extensions.Collections.csproj in [`e4c395c`](https://github.com/alastairlundy/CollectionExtensions/commit/e4c395c9964164606816b322606601fd7c1a8d1d)
* adjust namespaces in [`2b5474b`](https://github.com/alastairlundy/CollectionExtensions/commit/2b5474beff2bd4394c65fcf4a11b3535fd604367)
* move String Specializations to new directory in [`b46b1da`](https://github.com/alastairlundy/CollectionExtensions/commit/b46b1da312d3dc189aecccd5b901f8185cc61132)
* improve performance of AddRange extension in [`88721ef`](https://github.com/alastairlundy/CollectionExtensions/commit/88721ef0947d5fe63439cc7207ddbd20d8842a39)
* rename GetKey and GetKeys methods in [`89b2d8e`](https://github.com/alastairlundy/CollectionExtensions/commit/89b2d8e54ac39be7535dd17aa313d91f02ec6ac4)
* update copyright notices in [`14177c2`](https://github.com/alastairlundy/CollectionExtensions/commit/14177c23aa9463c105608bd00d1839ecc00d4880)

### Removed

* remove StringBuilder extension in [`a070dcb`](https://github.com/alastairlundy/CollectionExtensions/commit/a070dcba084d3da1540e03f287b4bcbf6e2464c2)
* remove redundant string overload in [`2fa7024`](https://github.com/alastairlundy/CollectionExtensions/commit/2fa70245ce7dc4af1a6a54f07f8d0cc9e9fccd7d)
* remove redundant replace extension in [`88efc9c`](https://github.com/alastairlundy/CollectionExtensions/commit/88efc9ca20b870dc5b6723b855f6f9945f59fb8e)
* remove duplicate solution file in [`3584d5f`](https://github.com/alastairlundy/CollectionExtensions/commit/3584d5ff61814bb35f1076bdaa94e38dbefd1fd9)
* remove System Extensions dependency in [`5151597`](https://github.com/alastairlundy/CollectionExtensions/commit/51515974df9a01780467c3c0e24ef892430736c5)
* remove Indexes code in [`d8bf995`](https://github.com/alastairlundy/CollectionExtensions/commit/d8bf9952d2a2357c3b27cff593ad6dad645836bd)
* remove DeDuplicate methods as unnecessary in [`51c9709`](https://github.com/alastairlundy/CollectionExtensions/commit/51c97090e42051f50ec601c10a3819cf057c4b32)
* remove deprecated code in [`24d432e`](https://github.com/alastairlundy/CollectionExtensions/commit/24d432e23349603e06f8c6bb2db4dd870b6672ec)

### Fixed

* fix build issues in [`4a3abac`](https://github.com/alastairlundy/CollectionExtensions/commit/4a3abac1edfccc9c8a227a4f2bc1773566e257e7)
* fix issue in [`ee297fe`](https://github.com/alastairlundy/CollectionExtensions/commit/ee297fe1b6792f6a8274d04c1bd2401cb8396285)