VOOZH about

URL: https://www.nuget.org/packages/SafeAgainst/

⇱ NuGet Gallery | SafeAgainst 8.0.1




👁 Image
SafeAgainst 8.0.1

dotnet add package SafeAgainst --version 8.0.1
 
 
NuGet\Install-Package SafeAgainst -Version 8.0.1
 
 
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="SafeAgainst" Version="8.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SafeAgainst" Version="8.0.1" />
 
Directory.Packages.props
<PackageReference Include="SafeAgainst" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SafeAgainst --version 8.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SafeAgainst, 8.0.1"
 
 
#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.
#:package SafeAgainst@8.0.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SafeAgainst&version=8.0.1
 
Install as a Cake Addin
#tool nuget:?package=SafeAgainst&version=8.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SafeAgainst

👁 Build
👁 SonarCloud workflow
👁 codecov

Provides functionality for creation of both synchronous and asynchronous generic guard clauses with custom preconditions and already contains implementation of basic ones for Collections, Enums, Strings, Objects and Numeric types.

Usage

  1. Eliminate Leading or trailing white spaces
  • passing value by reference:
 // Arrange
 var expectedValue = "Without leading or trailing whitespaces";
 var value = $" {expectedValue} ";

 // Act
 StringGuards.Safe.AgainstLeadingOrTrailingWhiteSpaces(ref value);

 // Assert
 Assert.Equal(expectedValue, value);
  • or using a SafeContainer:
 // Arrange
 var expectedValue = "Without leading or trailing whitespaces";
 var value = $" {expectedValue} ";
 var container = SafeContainer.Create(value);

 // Act
 StringGuards.Safe.AgainstLeadingOrTrailingWhiteSpaces(container);
 value = container.Value;

 // Assert
 Assert.Equal(expectedValue, value);
  1. Assigning a predefined value, if enum contains an invalid one
  • passing value by reference:
internal enum PowerOfTwo
{
 One = 1,
 Two = 2,
 Four = 4,
 Eight = 8,
 Sixteen = 16
};
 // Arrange
 PowerOfTwo powerOfTwo = default;
 var initialValue = powerOfTwo;

 // Act
 EnumGuards.Safe<PowerOfTwo>.AgainstNotInRange(ref powerOfTwo, PowerOfTwo.One);

 // Assert
 Assert.True(initialValue == 0);
 Assert.Equal(powerOfTwo, PowerOfTwo.One);
  • or using a SafeContainer:
 // Arrange
 PowerOfTwo powerOfTwo = default;
 var initialValue = powerOfTwo;
 var container = SafeContainer<PowerOfTwo>.Create(powerOfTwo);

 // Act
 EnumGuards.Safe<PowerOfTwo>.AgainstNotInRange(container, PowerOfTwo.One);
 powerOfTwo = container.Value;

 // Assert
 Assert.True(initialValue == 0);
 Assert.Equal(PowerOfTwo.One, powerOfTwo);
  1. Eliminating NULL elements from collection:
  • passing value by reference:
 // Arrange
 IEnumerable<int?> enumeration = Enumerable.Empty<int?>()
 .Append(2)
 .Append(10)
 .Append(null)
 .Append(1);

 // Act
 CollectionGuards.Safe<int?>.AgainstNullElements(ref enumeration);

 // Assert
 Assert.DoesNotContain(enumeration, x => x == null);
 Assert.Contains(enumeration, x => x != null);
 Assert.True(enumeration.ToList().Count == 3);
  • or using a SafeContainer:
 // Arrange
 IEnumerable<int?> enumeration = Enumerable.Empty<int?>()
 .Append(2)
 .Append(10)
 .Append(null)
 .Append(1);
 var container = SafeContainer.Create(enumeration);

 // Act
 CollectionGuards.Safe<int?>.AgainstNullElements(container);
 enumeration = container.Value;

 // Assert
 Assert.DoesNotContain(enumeration, x => x == null);
 Assert.Contains(enumeration, x => x != null);
 Assert.True(enumeration.ToList().Count == 3);

See way much more examples in the unit tests from the corresponding source repository.

Global Picture

👁 General picture

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SafeAgainst:

Package Downloads
WcfClient.Dynamic

This package simplifies the process of consuming web endpoints of SOAP style, allowing dynamic (re)configuration of endpoint address, binding type, and all related data within appsettings. Incoming and outgoing messages, as well as other properties, can be configured using this package.

SafeAgainst.Extensions

Provides extension methods for both synchronous and asynchronous guard clauses for generic types, as well as for Enums, Objects, Collections, Strings, and various numeric types encapsulated in 'SafeContainer'.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.1 1,439 6/2/2024
8.0.0 279 2/24/2024
7.0.1 240 6/23/2024
7.0.0 245 2/17/2024
6.0.0 320 2/10/2024
5.0.0 288 2/4/2024
3.1.0 253 1/27/2024
3.0.0 295 1/17/2024
2.2.0 269 1/13/2024
2.1.0 299 1/7/2024
2.0.0 296 1/3/2024
1.1.0 314 12/30/2023
1.0.0 301 12/27/2023

No code smells or other issues based on the default Sonarcloud check