Skip to content
Static-CodesPublic

About

A lightweight C# lib for path classification and validation in .NET 10.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A lightweight C# lib for path classification and validation in .NET 10.

Coming in at only 22 kilobytes when compiled, its small but powerful, supporting Windows 10/11, macOS 14+, FreeBSD, and any Linux distro supporting .NET 10.

Usage

// The following example validates that the Unix user binary directory is indeed:
// - A directory
// - Reserved by the Unix file system.

using static SafePath.Library;

var path = "/usr/bin";

// Single flags are also supported.
// Below shows two flags being evaluated with a bitwise OR operator. 
var flags = ValidationFlags.IsDirectory | ValidationFlags.IsReserved;
var result = Validate(path, flags);

Console.WriteLine($"Validation: {result.IsValid ? \"Passed\" : \"Failed\""});
// The following example validates that the Unix user binary directory is:
// - NOT a file
// - NOT a symlink.

using static SafePath.Library;

var path = "/usr/bin";

// Single flags are also supported.
// Below shows two flags being evaluated with a bitwise OR operator. 
var flags = ValidationFlags.IsNotFile | ValidationFlags.IsNotSymlink;
var result = Validate(path, flags);

Console.WriteLine($"Validation: {result.IsValid ? \"Passed\" : \"Failed\""});

Note: Validate(path, flags) returns a PathValidationResult record.

FlagDescription
None 

No flags were requested or identified.

IsNotBlockDevice 

Checks if the path doesn't represent a block device.

IsNotDirectory 

Checks if the path doesn't represent a directory.

IsNotFile 

Checks if the path doesn't represent a file.

IsNotPipe 

Checks if the path doesn't represent a pipe (fifo).

IsNotSymlink 

Checks if the path doesn't represent a symlink.

IsNotSocket 

Checks if the path doesn't represent a Unix socket.

IsNotReserved 

Checks if the path is not reserved by one of the 4 supported OS.

IsBlockDevice 

Checks if the path represents a Unix block device.

IsDirectory 

Checks if the path represents a directory.

IsFile 

Checks if the path represents a file.

IsPipe 

Checks if the path represents a named pipe (fifo).

IsSymlink 

Checks if the path represents a symbolic link.

IsSocket 

Checks if the path represents a Unix socket.

IsReserved 

Checks if the path is reserved by one of the 4 supported OS.

About

A lightweight C# lib for path classification and validation in .NET 10.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages