Add DirectoryName type and improve path validation semantics#3
Merged
matt-edmondson merged 1 commit intomainfrom Jan 6, 2026
Merged
Add DirectoryName type and improve path validation semantics#3matt-edmondson merged 1 commit intomainfrom
matt-edmondson merged 1 commit intomainfrom
Conversation
Introduce DirectoryName as a new semantic type for single directory name components (without path separators), providing better type safety and clarity when working with path segments. New types: - DirectoryName: Semantic string for single directory names - IDirectoryName: Marker interface for directory name types - IsValidDirectoryNameAttribute: Validates directory names (no path separators, only valid filename characters) Enhanced path operators: - AbsoluteDirectoryPath / DirectoryName → AbsoluteDirectoryPath - DirectoryPath / DirectoryName → DirectoryPath Type corrections: - RelativeDirectoryPath.Name now returns DirectoryName (was FileName) More semantically correct for representing a directory's name Validation improvements: - Replace IsFileNameAttribute with IsValidFileNameAttribute - Remove redundant validation attributes from RelativeDirectoryPath and RelativeFilePath (IsDirectoryPath, IsFilePath) - Focus on format-only validation without file system checks This change provides clearer semantics: use DirectoryName for single components like "src" or "bin", and RelativeDirectoryPath for multi-segment paths like "../folder" or ".\src\app".
|
Darcy3000s
approved these changes
Jan 6, 2026
Damon3000s
reviewed
Jan 6, 2026
| [SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Path combination is the semantic meaning, not mathematical division")] | ||
| public static DirectoryPath operator /(DirectoryPath left, DirectoryName right) | ||
| { | ||
| #if NET6_0_OR_GREATER |
There was a problem hiding this comment.
These guards exist here but not in the / overload within AbsoluteDirectoryPath.
Either this is not required here, or it needs to be added to the other location?
Damon3000s
reviewed
Jan 6, 2026
| ArgumentNullExceptionPolyfill.ThrowIfNull(right); | ||
| #endif | ||
|
|
||
| string combinedPath = Path.Combine(left.WeakString, right.WeakString); |
There was a problem hiding this comment.
Should this use PooledStringBuilder like the other function, or should the other function not use it? (or is both valid)
Damon3000s
reviewed
Jan 6, 2026
| public void IsValidDirectoryNameAttribute_EmptyDirectoryName_ShouldPass() | ||
| { | ||
| // Arrange | ||
| TestDirectoryName emptyName = TestDirectoryName.Create<TestDirectoryName>(""); |
There was a problem hiding this comment.
Shouldn't an empty folder name be invalid?
Damon3000s
reviewed
Jan 6, 2026
| [TestMethod] | ||
| public void IsValidDirectoryNameAttribute_DirectoryNameWithColon_ShouldFail() | ||
| { | ||
| // Arrange & Act & Assert - colon is invalid in directory names (except drive letters) |
Damon3000s
reviewed
Jan 6, 2026
| Assert.IsTrue(specialCharsName.IsValid()); | ||
| } | ||
|
|
||
| [TestMethod] |
There was a problem hiding this comment.
These tests seem mostly duplicated in DirectoryNameTests. Since this file is PathValidation should it be testing the path combination (which it probably already is)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Introduce DirectoryName as a new semantic type for single directory name components (without path separators), providing better type safety and clarity when working with path segments.
New types:
Enhanced path operators:
Type corrections:
Validation improvements:
This change provides clearer semantics: use DirectoryName for single components like "src" or "bin", and RelativeDirectoryPath for multi-segment paths like "../folder" or ".\src\app".