TryAtSoftware.Extensions.Collections
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package TryAtSoftware.Extensions.Collections --version 1.0.0
NuGet\Install-Package TryAtSoftware.Extensions.Collections -Version 1.0.0
<PackageReference Include="TryAtSoftware.Extensions.Collections" Version="1.0.0" />
paket add TryAtSoftware.Extensions.Collections --version 1.0.0
#r "nuget: TryAtSoftware.Extensions.Collections, 1.0.0"
// Install TryAtSoftware.Extensions.Collections as a Cake Addin #addin nuget:?package=TryAtSoftware.Extensions.Collections&version=1.0.0 // Install TryAtSoftware.Extensions.Collections as a Cake Tool #tool nuget:?package=TryAtSoftware.Extensions.Collections&version=1.0.0
About the project
TryAtSoftware.Extensions.Collection
is a library containing extension methods that should simplify some common operations with collections.
About us
Try At Software
is a software development company based in Bulgaria. We are mainly using dotnet
technologies (C#
, ASP.NET Core
, Entity Framework Core
, etc.) and our main idea is to provide a set of tools that can simplify the majority of work a developer does on a daily basis.
Getting started
OrEmptyIfNull
This is an extension method that will return an empty enumerable if the extended one was null.
The main use case is to prevent unnecessary exceptions whenever a null
enumerable should not be treated differently than an empty
enumerable.
Let's look at this example:
IEnumerable<int> numbers = /* initialization... */;
// 1. Iterating an `IEnumerable<T>` instance
if (numbers != null)
{
foreach (int num in numbers) { /* Do something */ }
}
// 2. Passing an `IEnumerable<T>` instance to other methods
string text;
if (numbers == null) text = string.Empty;
else text = string.Join(", ", numbers);
It can be improved like this:
IEnumerable<int> numbers = /* initialization... */;
// 1. Iterating an `IEnumerable<T>` instance
foreach (int num in numbers.OrEmptyIfNull()) { /* Do something */ }
// 2. Passing an `IEnumerable<T>` instance to other methods
string text = string.Join(", ", numbers.OrEmptyIfNull());
IgnoreNullValues
This is an extension method that will return a new enumerable containing all values from the extended one that are not null
in the same order.
The main use case is to reduce the amount of conditions when iterating a collection of elements.
Let's look at this example:
IEnumerable<string> words = /* initialization... */;
if (words != null)
{
foreach (string w in words)
{
if (w == null) continue;
/* Do something */
}
}
It can be improved like this:
IEnumerable<string> words = /* initialization... */;
foreach (string w in words.OrEmptyIfNull().IgnoreNullValues())
{
// Do something
}
IgnoreDefaultValues
This is an extension method that will return a new enumerable containing all values from the extended one that do not equal the default one in the same order. The main use case is to reduce the amount of conditions when iterating a collection of elements.
Let's look at this example:
IEnumerable<Guid> identifiers = /* initialization... */;
if (identifiers != null)
{
foreach (Guid id in identifiers)
{
if (id == Guid.Empty) continue;
/* Do something */
}
}
It can be improved like this:
IEnumerable<Guid> identifiers = /* initialization... */;
foreach (Guid id in identifiers.OrEmptyIfNull().IgnoreDefaultValues())
{
// Do something
}
SafeWhere
This is an extension method that can be used to filter the elements of the extended enumerable
safely in terms of the nullability of the predicate
.
Let's look at this example:
IEnumerable<Guid> identifiers = /* initialization... */;
if (identifiers != null)
{
Predicate<Guid> predicate = /* initialization... */;
if (predicate != null) identifiers = identifiers.Where(predicate);
foreach (Guid id in identifiers)
{
/* Do something */
}
}
It can be improved like this:
IEnumerable<Guid> identifiers = /* initialization... */;
Predicate<Guid> predicate = /* initialization... */;
foreach (Guid id in identifiers.OrEmptyIfNull().SafeWhere(predicate))
{
// Do something
}
ConcatenateWith
This is an extension method that can be used to concatenate two collections safely in terms of their nullability. Let's look at this example:
IEnumerable<int> a = /* initialization... */;
IEnumerable<int> b = /* initialization... */;
IEnumerable<int> concatenated;
if (a == null && b == null) concatenated = Enumerable.Empty<int>();
else if (a == null) concatenated = b;
else if (b == null) concatenated = a;
else
{
List<int> tempConcatenated = new List<int>();
foreach (int el in a) tempConcatenated.Add(el);
foreach (int el in b) tempConcatenated.Add(el);
concatenated = tempConcatenated;
}
It can be improved like this:
IEnumerable<int> a = /* initialization... */;
IEnumerable<int> b = /* initialization... */;
IEnumerable<int> concatenated = a.ConcatenateWith(b);
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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on TryAtSoftware.Extensions.Collections:
Package | Downloads |
---|---|
TryAtSoftware.Extensions.Reflection
This is an internal package used to make work with reflection cleaner and easier than ever before. |
|
TryAtSoftware.Equalizer
This package should be used to make your assertion process in tests cleaner and easier than ever before. |
|
TryAtSoftware.CleanTests
This package should be used to generate multiple combinations for a test case (according to the applied setup) and thus make the process of writing tests cleaner and easier than ever before. |
|
TryAtSoftware.Extensions.DependencyInjection
This is an internal package containing extension methods and utility components that should simplify some common operations with dependency injection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.2 | 977 | 11/15/2023 |
1.1.2-alpha.6 | 90 | 9/8/2023 |
1.1.2-alpha.5 | 84 | 9/4/2023 |
1.1.2-alpha.4 | 81 | 9/4/2023 |
1.1.2-alpha.3 | 79 | 9/1/2023 |
1.1.2-alpha.2 | 88 | 8/30/2023 |
1.1.2-alpha.1 | 80 | 8/25/2023 |
1.1.0 | 801 | 1/1/2023 |
1.0.0 | 5,271 | 12/16/2022 |
1.0.0-alpha.2 | 264 | 1/29/2022 |
1.0.0-alpha.1 | 409 | 12/11/2021 |