ktsu.StrongStrings 1.2.26-pre.5

Prefix Reserved
This is a prerelease version of ktsu.StrongStrings.
There is a newer version of this package available.
See the version list below for details.
dotnet add package ktsu.StrongStrings --version 1.2.26-pre.5                
NuGet\Install-Package ktsu.StrongStrings -Version 1.2.26-pre.5                
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.StrongStrings" Version="1.2.26-pre.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.StrongStrings --version 1.2.26-pre.5                
#r "nuget: ktsu.StrongStrings, 1.2.26-pre.5"                
#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 ktsu.StrongStrings as a Cake Addin
#addin nuget:?package=ktsu.StrongStrings&version=1.2.26-pre.5&prerelease

// Install ktsu.StrongStrings as a Cake Tool
#tool nuget:?package=ktsu.StrongStrings&version=1.2.26-pre.5&prerelease                

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

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (5)

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

Package Downloads
ktsu.Extensions

A utility library of extension methods to enhance the functionality of collections, enumerables, dictionaries, strings, and reflection in .NET

ktsu.StrongPaths

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

ktsu.AppDataStorage

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

ktsu.CredentialCache

CredentialCache

ktsu.GitIntegration

Git Integration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.26 532 12/28/2024
1.2.26-pre.9 2 1/8/2025
1.2.26-pre.8 33 1/7/2025
1.2.26-pre.7 35 1/6/2025
1.2.26-pre.6 54 1/4/2025
1.2.26-pre.5 41 1/3/2025
1.2.26-pre.4 42 1/3/2025
1.2.26-pre.3 43 1/3/2025
1.2.26-pre.2 51 1/1/2025
1.2.26-pre.1 43 12/27/2024
1.2.25 565 12/26/2024
1.2.24 73 12/26/2024
1.2.23 77 12/26/2024
1.2.22 72 12/26/2024
1.2.21 69 12/26/2024
1.2.20 85 12/26/2024
1.2.19 83 12/26/2024
1.2.18 1,362 12/23/2024
1.2.17 71 12/23/2024
1.2.16 75 12/23/2024
1.2.15 1,942 12/4/2024
1.2.14 557 12/2/2024
1.2.13 565 11/30/2024
1.2.12 85 11/30/2024
1.2.11 694 11/20/2024
1.2.10 922 11/13/2024
1.2.9 903 11/1/2024
1.2.8 1,626 10/4/2024
1.2.7 884 9/19/2024
1.2.6 322 9/19/2024
1.2.5 250 9/19/2024
1.2.4 108 9/18/2024
1.2.3 108 9/18/2024
1.2.2 210 9/18/2024
1.2.1 410 9/18/2024
1.2.0 533 9/18/2024
1.1.1 418 9/14/2024
1.1.0 102 9/14/2024

## v1.2.26 (patch)

Changes since v1.2.25:

- Add conditional build arguments for dotnet build command ([@matt-edmondson](https://github.com/matt-edmondson))
- Renamed metadata files ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.21 (patch)

Changes since v1.2.20:

- Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.16 (patch)

Changes since v1.2.15:

- Refactor assertions and add suppress warnings ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.13 (patch)

Changes since v1.2.12:

- Refactor MakeCanonical and As methods in AnyStrongString ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.12 (patch)

Changes since v1.2.11:

- Refactor AnyStrongString with MakeCanonical method ([@matt-edmondson](https://github.com/matt-edmondson))
- Suppress CA1859 warning and re-indent PreBuild target ([@matt-edmondson](https://github.com/matt-edmondson))
- Update namespace from ktsu.io.StrongStrings to ktsu.StrongStrings ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.7 (patch)

Changes since v1.2.6:

- Change build schedule to nightly and on push ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.6 (patch)

Changes since v1.2.5:

- Fix concurrency and run every 5 mins ([@matt-edmondson](https://github.com/matt-edmondson))
- Update dotnet.yml ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.0 (minor)

Changes since 1.1.0:

- Add an As method to convert between different types of string strings ([@matt-edmondson](https://github.com/matt-edmondson))
- Migrate ktsu.io to ktsu namespace ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.0.1 (major)

Changes since 0.0.0.0:

- Add a JsonConverter for use with System.Text.Json ([@matt-edmondson](https://github.com/matt-edmondson))
- Add builtin json convertor for System.Text.Json ([@matt-edmondson](https://github.com/matt-edmondson))
- Add github package support ([@matt-edmondson](https://github.com/matt-edmondson))
- Add more unit tests ([@matt-edmondson](https://github.com/matt-edmondson))
- Assign dependabot PRs to matt ([@matt-edmondson](https://github.com/matt-edmondson))
- Avoid double upload of symbols package ([@matt-edmondson](https://github.com/matt-edmondson))
- Bump version to 1.0.0-alpha.2 ([@matt-edmondson](https://github.com/matt-edmondson))
- Code style cleanup and add symbols and source to the nuget package ([@matt-edmondson](https://github.com/matt-edmondson))
- Correct a typo in the namespace ([@matt-edmondson](https://github.com/matt-edmondson))
- Create dependabot-merge.yml ([@matt-edmondson](https://github.com/matt-edmondson))
- Dont try to push packages when building pull requests ([@matt-edmondson](https://github.com/matt-edmondson))
- Enable dependabot and sourcelink ([@matt-edmondson](https://github.com/matt-edmondson))
- Fix a bunch of interface problems and add a unit test project ([@matt-edmondson](https://github.com/matt-edmondson))
- Fix build to properly read variables from files ([@matt-edmondson](https://github.com/matt-edmondson))
- Fix some style warnings ([@matt-edmondson](https://github.com/matt-edmondson))
- Formatted with resharper and add t4 templating for the inheritance hierarchy ([@matt-edmondson](https://github.com/matt-edmondson))
- Implement the full interface of System.String and add support for validators ([@matt-edmondson](https://github.com/matt-edmondson))
- Initial commit ([@matt-edmondson](https://github.com/matt-edmondson))
- Make code generation use csx rather than t4 so that it works with Rider ([@matt-edmondson](https://github.com/matt-edmondson))
- Migrate from .project.props to Directory.Build.props ([@matt-edmondson](https://github.com/matt-edmondson))
- Read from AUTHORS file during build ([@matt-edmondson](https://github.com/matt-edmondson))
- Read from VERSION when building ([@matt-edmondson](https://github.com/matt-edmondson))
- Read PackageDescription from DESCRIPTION file ([@matt-edmondson](https://github.com/matt-edmondson))
- Rearrange the inheritance hierarchy to be better and split out tests into categories ([@matt-edmondson](https://github.com/matt-edmondson))
- Rearrange the interface/base class to make using it as a parameter, casting to derived types, and calling statics easier ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor empty array returns in AnyStrongString ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove obsolete t4 junk from project file ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove old resharper settings ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove suffix methods with are now in ktsu.io.Extensions, and do a cleanup of old cruft ([@matt-edmondson](https://github.com/matt-edmondson))
- Test signing ([@matt-edmondson](https://github.com/matt-edmondson))
- Update build config ([@matt-edmondson](https://github.com/matt-edmondson))
- Update build scripts ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.props ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.targets ([@matt-edmondson](https://github.com/matt-edmondson))
- Update dotnet.yml ([@matt-edmondson](https://github.com/matt-edmondson))
- Update github workflow to support submodules ([@matt-edmondson](https://github.com/matt-edmondson))
- Update LICENSE ([@matt-edmondson](https://github.com/matt-edmondson))
- Update nuget.config ([@matt-edmondson](https://github.com/matt-edmondson))
- Update readme and description ([@matt-edmondson](https://github.com/matt-edmondson))
- Update README.md ([@matt-edmondson](https://github.com/matt-edmondson))
- Upgrade actions ([@matt-edmondson](https://github.com/matt-edmondson))
- Use environment files for reading VERSION as set-output is deprecated ([@matt-edmondson](https://github.com/matt-edmondson))
- Use fully qualified names for templated types to avoid having to provide the namespace ([@matt-edmondson](https://github.com/matt-edmondson))
- v1.0.0-alpha.6 ([@matt-edmondson](https://github.com/matt-edmondson))