OnlyValidationTypes 1.1.0

dotnet add package OnlyValidationTypes --version 1.1.0
                    
NuGet\Install-Package OnlyValidationTypes -Version 1.1.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="OnlyValidationTypes" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OnlyValidationTypes" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="OnlyValidationTypes" />
                    
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 OnlyValidationTypes --version 1.1.0
                    
#r "nuget: OnlyValidationTypes, 1.1.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.
#:package OnlyValidationTypes@1.1.0
                    
#: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=OnlyValidationTypes&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=OnlyValidationTypes&version=1.1.0
                    
Install as a Cake Tool

Only Validations Type

Contains small, easy to use types, which cover the most common use cases for validations.

The main goal with these types is to assure that the data is valid, and that the data is in the correct format. They might also include some other functionality for improved ease of use.

Current Types

NonEmptyString

This type ensures that a string is not empty, whitespace or null.

// Constructor
var validString = new NonEmptyString("Hello World");
var invalidString = new NonEmptyString(" "); // Throws

// Factory method
var validString = NonEmptyString.Create("Hello World");
var invalidString = NonEmptyString.Create(" "); // Throws

// Implicit conversion
NonEmtpyString validString = "Hello World";
NonEmptyString invalidString = " "; // Throws

Base64String

// Constructor
var validBase64 = new Base64String("SGVsbG8gV29ybGQ=");
var invalidBase64 = new Base64String(" "); // Throws
var alsoInvalidBase64 = new Base64String("Hello World"); // Throws

// Factory method
var validBase64 = Base64String.Create("SGVsbG8gV29ybGQ=");
var invalidBase64 = Base64String.Create(" "); // Throws
var alsoInvalidBase64 = Base64String.Create("Hello World"); // Throws

// Implicit conversion
Base64String validBase64 = "SGVsbG8gV29ybGQ=";
Base64String invalidBase64 = " "; // Throws
Base64String alsoInvalidBase64 = "Hello World"; // Throws

HtmlString

// Constructor
var validHtml = new HtmlString("<p>Hello World</p>");
var invalidHtml = new HtmlString(" "); // Throws

... you get the idea
    
// HtmlString contains a method to strip all the html
var plainText = validHtml.StripHtml(); // "Hello World"

// HtmlString contains a property for SanitizationInfo
var info = validHtml.SanitizationInfo;
public readonly partial record struct SanitizationInfo(
    ImmutableArray<RemovedElementInfo> RemovedElements
);

public readonly partial record struct RemovedElementInfo(
    string TagName,
    string? ElementName,
    string Reason,
    string? Position
);

CultureCode

// Constructor
var validCultureCode = new CultureCode("en-US");
var invalidCultureCode = new CultureCode(" "); // Throws
var alsoInvalidCultureCode = new CultureCode("Hello World"); // Throws

...
    
// CultureCode contains a property for CultureInfo
var cultureInfo = validCultureCode.CultureInfo; // en-Us CultureInfo
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 206 1/4/2025
1.0.1 174 1/4/2025
1.0.0 176 1/4/2025