ktsu.StrongPaths
1.3.2
Prefix Reserved
dotnet add package ktsu.StrongPaths --version 1.3.2
NuGet\Install-Package ktsu.StrongPaths -Version 1.3.2
<PackageReference Include="ktsu.StrongPaths" Version="1.3.2" />
<PackageVersion Include="ktsu.StrongPaths" Version="1.3.2" />
<PackageReference Include="ktsu.StrongPaths" />
paket add ktsu.StrongPaths --version 1.3.2
#r "nuget: ktsu.StrongPaths, 1.3.2"
#:package ktsu.StrongPaths@1.3.2
#addin nuget:?package=ktsu.StrongPaths&version=1.3.2
#tool nuget:?package=ktsu.StrongPaths&version=1.3.2
ktsu.StrongPaths
A library providing strong typing for common filesystem paths with compile-time feedback and runtime validation
Introduction
StrongPaths is a collection of classes derived from ktsu.StrongStrings with added functionality and helper methods for filesystem paths. It provides strong typing for common filesystem paths, giving you compile-time feedback and runtime validation to help catch path-related errors early in your development cycle.
Get familiar with the StrongStrings library to get the most out of StrongPaths.
Features
- Strong Typing for file system paths to prevent type confusion
- Path Combination using overloaded operators for intuitive path building
- Compile-time Safety to catch type mismatches early
- Runtime Validation for path format and structure
- Relative Path Calculations between different path types
- Hierarchical Type System for flexible parameter constraints
Installation
Package Manager Console
Install-Package ktsu.StrongPaths
.NET CLI
dotnet add package ktsu.StrongPaths
Package Reference
<PackageReference Include="ktsu.StrongPaths" Version="x.y.z" />
Usage Examples
Basic Example
using ktsu.StrongPaths;
// Create strongly-typed paths
AbsoluteDirectoryPath rootDir = (AbsoluteDirectoryPath)@"C:\Projects";
RelativeDirectoryPath subDir = (RelativeDirectoryPath)"MyProject";
FileName configFile = (FileName)"config.json";
// Combine paths with the / operator
AbsoluteFilePath fullPath = rootDir / subDir / configFile;
// Use with standard file operations
File.WriteAllText(fullPath, "{ \"setting\": \"value\" }");
Path Combining with Operators
using ktsu.StrongPaths;
public class MyDemoClass
{
public AbsoluteDirectoryPath OutputDir { get; set; } = (AbsoluteDirectoryPath)@"c:\output";
public void SaveData(RelativeDirectoryPath subDir, FileName fileName)
{
// You can use the / operator to combine paths
AbsoluteFilePath filePath = OutputDir / subDir / fileName;
File.WriteAllText(filePath, "Hello, world!");
// An AbsoluteDirectoryPath combined with a RelativeDirectoryPath returns an AbsoluteDirectoryPath
AbsoluteDirectoryPath newOutputDir = OutputDir / subDir;
// An AbsoluteDirectoryPath combined with a FileName returns an AbsoluteFilePath
AbsoluteFilePath newFilePath = newOutputDir / fileName;
}
}
Calculating Relative Paths
using ktsu.StrongPaths;
AbsoluteDirectoryPath baseDir = (AbsoluteDirectoryPath)@"C:\Projects\MainProject";
AbsoluteDirectoryPath targetDir = (AbsoluteDirectoryPath)@"C:\Projects\MainProject\Submodule\Source";
AbsoluteFilePath targetFile = (AbsoluteFilePath)@"C:\Projects\MainProject\Submodule\Source\Program.cs";
// Get relative paths from one location to another
RelativeDirectoryPath relativeDir = targetDir.RelativeTo(baseDir); // "Submodule\Source"
RelativeFilePath relativeFile = targetFile.RelativeTo(baseDir); // "Submodule\Source\Program.cs"
Advanced Usage
Using Abstract Base Classes
You can use abstract base classes to accept a subset of path types in your method parameters:
using ktsu.StrongPaths;
public static class MyDemoClass
{
public static void SaveData(AnyDirectoryPath outputDir, FileName fileName)
{
// You can't use the / operator with the abstract base classes because it has no way of knowing which type to return
// You have to use the Path.Combine method when using the abstract base classes
FilePath filePath = (FilePath)Path.Combine(outputDir, fileName);
File.WriteAllText(filePath, "Hello, World!");
}
public static void Demo()
{
string storeLocation = "melbourne";
RelativeDirectoryPath storeDir = (RelativeDirectoryPath)$"store_{storeLocation}";
FileName fileName = (FileName)$"{DateTime.UtcNow}.json";
SaveData(storeDir, fileName);
}
}
Path Validation and Creation
using ktsu.StrongPaths;
// Validate paths at creation
try
{
// This will throw if the path is invalid
AbsoluteFilePath invalidPath = (AbsoluteFilePath)"not:a:valid:path";
}
catch (FormatException ex)
{
Console.WriteLine("Invalid path format: " + ex.Message);
}
// Create a directory if it doesn't exist
AbsoluteDirectoryPath projectDir = (AbsoluteDirectoryPath)@"C:\Projects\NewProject";
if (!Directory.Exists(projectDir))
{
Directory.CreateDirectory(projectDir);
}
API Reference
Available Types
Concrete Types
| Type | Description |
|---|---|
AbsolutePath |
Base type for all absolute paths |
RelativePath |
Base type for all relative paths |
DirectoryPath |
Base type for all directory paths |
FilePath |
Base type for all file paths |
FileName |
Represents just a filename with extension |
FileExtension |
Represents just a file extension |
AbsoluteDirectoryPath |
Represents an absolute directory path |
RelativeDirectoryPath |
Represents a relative directory path |
AbsoluteFilePath |
Represents an absolute file path |
RelativeFilePath |
Represents a relative file path |
Abstract Base Classes
| Type | Accepted Derived Types |
|---|---|
AnyStrongPath |
All concrete path types |
AnyRelativePath |
RelativePath, RelativeDirectoryPath, RelativeFilePath |
AnyAbsolutePath |
AbsolutePath, AbsoluteDirectoryPath, AbsoluteFilePath |
AnyDirectoryPath |
DirectoryPath, AbsoluteDirectoryPath, RelativeDirectoryPath |
AnyFilePath |
FilePath, AbsoluteFilePath, RelativeFilePath |
Key Operations
| Operation | Description |
|---|---|
/ operator |
Combines paths with appropriate type safety |
RelativeTo(...) |
Calculates a relative path between two locations |
| Type casting | Convert between string and path types with validation |
Contributing
Contributions are welcome! Please feel free to submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
| Product | Versions 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. 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. |
-
net8.0
- ktsu.Extensions (>= 1.5.5)
- ktsu.StrongStrings (>= 1.4.2)
-
net9.0
- ktsu.Extensions (>= 1.5.5)
- ktsu.StrongStrings (>= 1.4.2)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on ktsu.StrongPaths:
| Package | Downloads |
|---|---|
|
ktsu.ImGuiApp
A comprehensive .NET library that provides complete application scaffolding for Dear ImGui applications, featuring window management, DPI-aware rendering, precision PID-controlled frame limiting with comprehensive auto-tuning, advanced font handling with Unicode/emoji support, texture management, and debug tooling. Built on Silk.NET for cross-platform OpenGL support and Hexa.NET.ImGui for modern Dear ImGui bindings. |
|
|
ktsu.ImGuiWidgets
A library of custom widgets using ImGui.NET and utilities to enhance ImGui-based applications. |
|
|
ktsu.ImGuiPopups
A library for custom popups using ImGui.NET. |
|
|
ktsu.CredentialCache
CredentialCache |
|
|
ktsu.GitIntegration
Git Integration |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.3.2 | 2,034 | 5/21/2025 | |
| 1.3.2-pre.17 | 173 | 5/20/2025 | |
| 1.3.2-pre.15 | 125 | 5/17/2025 | |
| 1.3.2-pre.14 | 175 | 5/16/2025 | |
| 1.3.2-pre.13 | 245 | 5/15/2025 | |
| 1.3.2-pre.12 | 247 | 5/14/2025 | |
| 1.3.2-pre.11 | 251 | 5/13/2025 | |
| 1.3.2-pre.10 | 266 | 5/12/2025 | |
| 1.3.2-pre.9 | 224 | 5/11/2025 | |
| 1.3.2-pre.8 | 157 | 5/10/2025 | |
| 1.3.2-pre.7 | 95 | 5/9/2025 | |
| 1.3.2-pre.6 | 170 | 5/8/2025 | |
| 1.3.2-pre.5 | 146 | 5/7/2025 | |
| 1.3.2-pre.4 | 162 | 5/6/2025 | |
| 1.3.2-pre.3 | 155 | 5/5/2025 | |
| 1.3.2-pre.2 | 168 | 5/4/2025 | |
| 1.3.2-pre.1 | 160 | 5/4/2025 | |
| 1.3.1 | 3,489 | 5/4/2025 | |
| 1.3.1-pre.2 | 109 | 4/26/2025 | |
| 1.3.1-pre.1 | 166 | 4/4/2025 | |
| 1.3.0 | 2,860 | 3/30/2025 | |
| 1.2.1-pre.3 | 132 | 3/29/2025 | |
| 1.2.1-pre.2 | 500 | 3/25/2025 | |
| 1.2.1-pre.1 | 127 | 2/18/2025 | |
| 1.2.0 | 2,684 | 2/17/2025 | |
| 1.1.51-pre.3 | 128 | 2/6/2025 | |
| 1.1.51-pre.2 | 114 | 2/5/2025 | |
| 1.1.51-pre.1 | 120 | 2/5/2025 | |
| 1.1.50 | 3,306 | 1/2/2025 | |
| 1.1.50-pre.28 | 101 | 2/4/2025 | |
| 1.1.50-pre.27 | 113 | 2/3/2025 | |
| 1.1.50-pre.26 | 93 | 2/2/2025 | |
| 1.1.50-pre.25 | 86 | 1/31/2025 | |
| 1.1.50-pre.24 | 106 | 1/29/2025 | |
| 1.1.50-pre.23 | 86 | 1/27/2025 | |
| 1.1.50-pre.22 | 88 | 1/25/2025 | |
| 1.1.50-pre.21 | 102 | 1/23/2025 | |
| 1.1.50-pre.20 | 89 | 1/21/2025 | |
| 1.1.50-pre.19 | 82 | 1/20/2025 | |
| 1.1.50-pre.18 | 86 | 1/19/2025 | |
| 1.1.50-pre.17 | 86 | 1/17/2025 | |
| 1.1.50-pre.16 | 96 | 1/15/2025 | |
| 1.1.50-pre.15 | 102 | 1/13/2025 | |
| 1.1.50-pre.14 | 87 | 1/11/2025 | |
| 1.1.50-pre.13 | 78 | 1/10/2025 | |
| 1.1.50-pre.12 | 90 | 1/10/2025 | |
| 1.1.50-pre.11 | 77 | 1/8/2025 | |
| 1.1.50-pre.10 | 110 | 1/7/2025 | |
| 1.1.50-pre.9 | 97 | 1/6/2025 | |
| 1.1.50-pre.8 | 108 | 1/4/2025 | |
| 1.1.50-pre.7 | 97 | 1/3/2025 | |
| 1.1.50-pre.6 | 94 | 1/3/2025 | |
| 1.1.50-pre.5 | 98 | 1/3/2025 | |
| 1.1.50-pre.4 | 106 | 1/1/2025 | |
| 1.1.50-pre.3 | 109 | 12/31/2024 | |
| 1.1.50-pre.2 | 91 | 12/29/2024 | |
| 1.1.50-pre.1 | 86 | 12/28/2024 | |
| 1.1.49 | 1,906 | 12/26/2024 | |
| 1.1.48 | 149 | 12/26/2024 | |
| 1.1.47 | 139 | 12/26/2024 | |
| 1.1.46 | 167 | 12/26/2024 | |
| 1.1.45 | 152 | 12/26/2024 | |
| 1.1.44 | 157 | 12/26/2024 | |
| 1.1.43 | 165 | 12/26/2024 | |
| 1.1.42 | 373 | 12/25/2024 | |
| 1.1.41 | 453 | 12/24/2024 | |
| 1.1.40 | 443 | 12/23/2024 | |
| 1.1.39 | 146 | 12/23/2024 | |
| 1.1.38 | 150 | 12/23/2024 | |
| 1.1.37 | 781 | 12/19/2024 | |
| 1.1.36 | 540 | 12/14/2024 | |
| 1.1.35 | 564 | 12/6/2024 | |
| 1.1.34 | 296 | 12/5/2024 | |
| 1.1.33 | 521 | 12/2/2024 | |
| 1.1.32 | 399 | 12/2/2024 | |
| 1.1.31 | 366 | 12/1/2024 | |
| 1.1.30 | 214 | 12/1/2024 | |
| 1.1.29 | 243 | 11/30/2024 | |
| 1.1.28 | 170 | 11/30/2024 | |
| 1.1.27 | 195 | 11/30/2024 | |
| 1.1.26 | 223 | 11/29/2024 | |
| 1.1.25 | 300 | 11/28/2024 | |
| 1.1.24 | 328 | 11/26/2024 | |
| 1.1.23 | 654 | 11/15/2024 | |
| 1.1.22 | 301 | 11/14/2024 | |
| 1.1.21 | 290 | 11/13/2024 | |
| 1.1.20 | 644 | 11/5/2024 | |
| 1.1.19 | 335 | 11/2/2024 | |
| 1.1.18 | 359 | 11/1/2024 | |
| 1.1.17 | 903 | 10/17/2024 | |
| 1.1.16 | 614 | 10/8/2024 | |
| 1.1.15 | 303 | 10/5/2024 | |
| 1.1.14 | 256 | 10/4/2024 | |
| 1.1.13 | 608 | 9/24/2024 | |
| 1.1.12 | 283 | 9/21/2024 | |
| 1.1.11 | 284 | 9/19/2024 | |
| 1.1.10 | 222 | 9/19/2024 | |
| 1.1.9 | 238 | 9/19/2024 | |
| 1.1.8 | 155 | 9/19/2024 | |
| 1.1.7 | 252 | 9/19/2024 | |
| 1.1.6 | 188 | 9/18/2024 | |
| 1.1.5 | 154 | 9/18/2024 | |
| 1.1.4 | 329 | 9/18/2024 | |
| 1.1.3 | 453 | 9/18/2024 | |
| 1.1.2 | 431 | 9/14/2024 |
## v1.3.2
Initial release or repository with no prior history.