![]() |
VOOZH | about |
dotnet add package ModelingEvolution.FileSystem --version 2.3.1
NuGet\Install-Package ModelingEvolution.FileSystem -Version 2.3.1
<PackageReference Include="ModelingEvolution.FileSystem" Version="2.3.1" />
<PackageVersion Include="ModelingEvolution.FileSystem" Version="2.3.1" />Directory.Packages.props
<PackageReference Include="ModelingEvolution.FileSystem" />Project file
paket add ModelingEvolution.FileSystem --version 2.3.1
#r "nuget: ModelingEvolution.FileSystem, 2.3.1"
#:package ModelingEvolution.FileSystem@2.3.1
#addin nuget:?package=ModelingEvolution.FileSystem&version=2.3.1Install as a Cake Addin
#tool nuget:?package=ModelingEvolution.FileSystem&version=2.3.1Install as a Cake Tool
Strongly-typed file system path handling for .NET with intuitive path arithmetic operators.
AbsolutePath, RelativePath, and FileExtension value types/ on Linux, \ on Windows)Parse, TryParse, and generic parsing APIsSystem.Text.Json support via JsonParsableConverterdotnet add package ModelingEvolution.FileSystem
using ModelingEvolution.FileSystem;
// Create paths (implicit conversion from string)
AbsolutePath projectRoot = "/home/user/projects/myapp"; // Linux
AbsolutePath projectRoot = @"C:\Projects\MyApp"; // Windows
RelativePath srcFolder = "src/components";
// Combine paths with + operator
AbsolutePath fullPath = projectRoot + srcFolder;
// Linux: /home/user/projects/myapp/src/components
// Windows: C:\Projects\MyApp\src\components
// Get relative path between absolutes with - operator
RelativePath relative = fullPath - projectRoot;
// Result: src/components (or src\components on Windows)
| Expression | Result | Description |
|---|---|---|
Relative + Relative |
RelativePath |
Combine two relative paths |
Absolute + Relative |
AbsolutePath |
Append relative path to absolute |
Absolute - Absolute |
RelativePath |
Get relative path between two absolutes |
// Relative + Relative = Relative
RelativePath src = "src";
RelativePath components = "components";
RelativePath combined = src + components; // src/components
// Absolute + Relative = Absolute
AbsolutePath root = "/projects";
AbsolutePath full = root + combined; // /projects/src/components
// Absolute - Absolute = Relative
AbsolutePath from = "/projects/app";
AbsolutePath to = "/projects/app/src/utils";
RelativePath diff = to - from; // src/utils
// Works with parent traversal
AbsolutePath sibling = "/projects/other";
RelativePath toSibling = sibling - from; // ../other
Paths are automatically normalized to the current platform's separator:
// On Linux - all separators become /
RelativePath path = "foo\\bar/baz";
Console.WriteLine((string)path); // foo/bar/baz
// On Windows - all separators become \
RelativePath path = "foo\\bar/baz";
Console.WriteLine((string)path); // foo\bar\baz
Mixed and duplicate separators are handled:
RelativePath path = "foo//bar\\\\baz";
// Normalized to: foo/bar/baz (Linux) or foo\bar\baz (Windows)
public readonly record struct RelativePath : IParsable<RelativePath>, IComparable<RelativePath>
{
// Construction
public RelativePath(string path);
public static readonly RelativePath Empty;
// Properties
public bool IsEmpty { get; }
public RelativePath FileName { get; }
public RelativePath FileNameWithoutExtension { get; }
public FileExtension Extension { get; }
public RelativePath Parent { get; }
public string[] Segments { get; }
// Methods
public RelativePath ChangeExtension(FileExtension newExtension);
// Operators
public static RelativePath operator +(RelativePath left, RelativePath right);
public static RelativePath operator +(RelativePath left, string right);
// Conversions (use these instead of .Value)
public static implicit operator RelativePath(string path);
public static implicit operator string(RelativePath path);
}
public readonly record struct AbsolutePath : IParsable<AbsolutePath>, IComparable<AbsolutePath>
{
// Construction
public AbsolutePath(string path);
// Properties
public RelativePath FileName { get; }
public RelativePath FileNameWithoutExtension { get; }
public FileExtension Extension { get; }
public AbsolutePath? Root { get; }
public AbsolutePath? Parent { get; }
// Methods
public AbsolutePath ChangeExtension(FileExtension newExtension);
public bool StartsWith(AbsolutePath basePath);
// Operators
public static AbsolutePath operator +(AbsolutePath left, RelativePath right);
public static AbsolutePath operator +(AbsolutePath left, string right);
public static RelativePath operator -(AbsolutePath right, AbsolutePath left);
// Conversions (use these instead of .Value)
public static implicit operator AbsolutePath(string path);
public static implicit operator string(AbsolutePath path);
}
public readonly record struct FileExtension : IParsable<FileExtension>, IComparable<FileExtension>
{
// Construction
public FileExtension(string extension);
public static readonly FileExtension None;
// Properties
public bool IsEmpty { get; }
public string WithDot { get; } // ".txt"
public string WithoutDot { get; } // "txt"
// Common extensions
public static FileExtension Txt { get; }
public static FileExtension Json { get; }
public static FileExtension Cs { get; }
public static FileExtension Md { get; }
// ... and more
// Methods
public bool IsOneOf(params FileExtension[] extensions);
public bool IsOneOf(params string[] extensions);
// Conversions
public static implicit operator FileExtension(string extension);
public static implicit operator string(FileExtension extension);
}
All types serialize as strings:
using System.Text.Json;
var config = new AppConfig
{
ProjectRoot = (AbsolutePath)"/projects/myapp",
SourceFolder = (RelativePath)"src/main",
OutputExtension = FileExtension.Json
};
string json = JsonSerializer.Serialize(config);
// {"ProjectRoot":"/projects/myapp","SourceFolder":"src/main","OutputExtension":".json"}
AbsolutePath outputDir = (AbsolutePath)config.BuildOutput;
RelativePath artifactPath = (RelativePath)"bin" + config.Configuration + config.TargetFramework;
AbsolutePath fullOutput = outputDir + artifactPath;
RelativePath file = "document.txt";
if (file.Extension.IsOneOf(".txt", ".md", ".rst"))
{
// Handle text files
var newFile = file.ChangeExtension(".html");
}
AbsolutePath docFile = (AbsolutePath)"/docs/api/classes/MyClass.md";
AbsolutePath imageFile = (AbsolutePath)"/docs/images/diagram.png";
RelativePath relativeLink = imageFile - docFile.Parent!.Value;
// Result: ../../images/diagram.png
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. 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. |
Showing the top 2 NuGet packages that depend on ModelingEvolution.FileSystem:
| Package | Downloads |
|---|---|
|
ModelingEvolution.Ide
Package Description |
|
|
ModelingEvolution.FileSystem.Blazor
Blazor FileExplorer component with MudBlazor for browsing local file systems. Uses IFileSystem abstraction for all operations. |
This package is not used by any popular GitHub repositories.