VOOZH about

URL: https://www.nuget.org/packages/ktsu.io.StrongStrings/

⇱ NuGet Gallery | ktsu.io.StrongStrings 1.1.0




ktsu.io.StrongStrings 1.1.0

Prefix Reserved
Suggested Alternatives

ktsu.StrongStrings

dotnet add package ktsu.io.StrongStrings --version 1.1.0
 
 
NuGet\Install-Package ktsu.io.StrongStrings -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="ktsu.io.StrongStrings" Version="1.1.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ktsu.io.StrongStrings" Version="1.1.0" />
 
Directory.Packages.props
<PackageReference Include="ktsu.io.StrongStrings" />
 
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 ktsu.io.StrongStrings --version 1.1.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ktsu.io.StrongStrings, 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 ktsu.io.StrongStrings@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=ktsu.io.StrongStrings&version=1.1.0
 
Install as a Cake Addin
#tool nuget:?package=ktsu.io.StrongStrings&version=1.1.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

StrongStrings

A library that provides a transparent wrapper around system strings and gives you strong typing, compile time feedback, and runtime validation.

The intention is to be able to provide usage context and validation to naked strings in a similar way that Enums do for integers.

Usage

using ktsu.io.StrongStrings;

// Create a strong type by deriving a record class from StrongStringAbstract<TDerived>:
public record class MyStrongString : StrongStringAbstract<MyStrongString> { }

public class MyDemoClass
{
	public MyStrongString Stronk { get; set; } = new();

	public static void Demo(MyStrongString inStrongString, string inSystemString, out MyStrongString outStrongString, out string outSystemString)
	{
		// You can implicitly cast down to a System.String
		outSystemString = inStrongString;

		// You must explicitly cast up to a StrongString
		outStrongString = (MyStrongString)inSystemString;

		//You can provide a StrongString to a method that expects a System.String
		Path.Combine(inStrongString, inSystemString);

		// You can use the .WeakString property or the .ToString() method to get the value of the underlying System.String
		outSystemString = inStrongString.WeakString;
		outSystemString = inStrongString.ToString();

		// You can not implicitly cast up to a StrongString
		// outStrongString = inSystemString; // This will not compile

		// You can not cast from one StrongString to another
		// OtherStrongString other = inStrongString; // This will not compile
		// OtherStrongString other = (OtherStrongString)inStrongString; // This will not compile either
	}
}

Validation

You can provide custom validators which will throw a FormatException at runtime to help you catch data errors.

Implement the ktsu.io.StrongStrings.IValidator interface and provide it as a generic parameter when deriving your class:

public abstract class StartsWithHttp : IValidator
{
	public static bool IsValid(AnyStrongString? strongString)
	{
		ArgumentNullException.ThrowIfNull(strongString);

		return strongString.StartsWith("http", StringComparison.InvariantCultureIgnoreCase);
	}
}

public abstract class EndsWithDotCom : IValidator
{
	public static bool IsValid(AnyStrongString? strongString)
	{
		ArgumentNullException.ThrowIfNull(strongString);

		return strongString.EndsWith(".com", StringComparison.InvariantCultureIgnoreCase);
	}
}

public record class MyValidatedString : StrongStringAbstract<MyValidatedString, StartsWithHttp, EndsWithDotCom> { }
Product Versions Compatible and additional computed target framework versions.
.NET net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  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.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ktsu.io.StrongStrings:

Package Downloads
ktsu.io.Extensions

Extension Methods for common operations to help with expressiveness and maintainability.

ktsu.io.StrongPaths

A library that provides strong typing for common filesystem paths providing compile time feedback and runtime validation.

ktsu.io.AppDataStorage

Application data management library using JSON serialization to save and load data in the user's app data folder.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 2,146 8/21/2024 1.1.0 is deprecated because it is no longer maintained.
1.0.1 3,586 3/20/2024
1.0.1-alpha.1 145 3/20/2024
1.0.0 297 3/7/2024
1.0.0-alpha.8 158 2/29/2024
1.0.0-alpha.7 217 2/28/2024
1.0.0-alpha.6 212 2/18/2024
1.0.0-alpha.5 129 2/18/2024
1.0.0-alpha.4 276 12/27/2023
1.0.0-alpha.3 147 12/26/2023
1.0.0-alpha.2 221 6/1/2023
1.0.0-alpha.1 197 5/24/2023