Skip to content

Conversation

@dennisdoomen
Copy link
Owner

@dennisdoomen dennisdoomen commented Oct 19, 2025

This PR implements support for using the C# range operator .. to navigate to parent directories, providing a more intuitive and concise syntax for path traversal.

Problem

Previously, navigating to parent directories required chaining multiple .Parent property accesses, which can become verbose:

var path = ChainablePath.Current.Parent.Parent.Parent / "file.txt";

Solution

With this change, you can now use the range operator .. for a cleaner syntax:

var path = ChainablePath.Current / .. / .. / .. / "file.txt";

This works exactly like the .Parent property but provides a more natural and readable way to express directory traversal.

Implementation Details

  • Added a new / operator overload that accepts a Range parameter
  • The operator validates that only the .. range operator (equivalent to Range.All) is used
  • Throws ArgumentException with a clear error message if any other range is provided (e.g., 1..3)
  • Available only on .NET 6.0+ and .NET Standard 2.1+ where the Range type is supported
  • Delegates to the existing Parent property to ensure consistent behavior

Examples

// Navigate up and then to a sibling directory
var testPath = projectPath / .. / "tests" / "UnitTests.cs";

// Equivalent to:
var testPath = projectPath.Parent / "tests" / "UnitTests.cs";

// Complex navigation
var docsPath = ChainablePath.Current / .. / .. / "docs" / "README.md";

// Equivalent to:
var docsPath = ChainablePath.Current.Parent.Parent / "docs" / "README.md";

Closes #83

@dennisdoomen dennisdoomen added the enhancement New feature or request label Oct 19, 2025
@github-actions
Copy link

github-actions bot commented Oct 19, 2025

Test Results

116 tests  +6   116 ✅ +6   1s ⏱️ -1s
  3 suites ±0     0 💤 ±0 
  3 files   ±0     0 ❌ ±0 

Results for commit c1a5458. ± Comparison against base commit 7418cc8.

♻️ This comment has been updated with latest results.

@dennisdoomen dennisdoomen force-pushed the add-range-operator-support branch from 00fb598 to 2bb8c18 Compare October 19, 2025 07:40
@coveralls
Copy link

coveralls commented Oct 19, 2025

Pull Request Test Coverage Report for Build 18627674698

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 97.101%

Totals Coverage Status
Change from base Build 18627324930: 0.1%
Covered Lines: 239
Relevant Lines: 247

💛 - Coveralls

@dennisdoomen dennisdoomen force-pushed the add-range-operator-support branch from 2bb8c18 to c1a5458 Compare October 19, 2025 08:12
@dennisdoomen dennisdoomen merged commit c59dc4b into main Oct 19, 2025
3 checks passed
@dennisdoomen dennisdoomen deleted the add-range-operator-support branch October 19, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow using .. (range operator) as a means to refer to the parent directory

3 participants