You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance semantic string type conversions and path handling
This commit introduces several improvements to the semantic string conversion API and path handling methods:
- Added a new extension method `As<TSource, TTarget>()` for converting between different semantic string types, providing a fluent syntax for type conversions.
- Consolidated the `AsAbsolute()` method across various path interfaces to return the appropriate concrete types, removing redundant methods like `AsAbsoluteFilePath()` and `AsAbsoluteDirectoryPath()`.
- Updated documentation for clarity on the new conversion methods and their usage.
- Enhanced unit tests to validate the new functionality and ensure correct behavior across different path types.
Copy file name to clipboardExpand all lines: .cursor/rules/derived-cursor-rules.mdc
+85Lines changed: 85 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -234,6 +234,91 @@ When adding XML documentation comments:
234
234
* **IDE0060 Warning**: Replace unused parameters with `_`.
235
235
* **Semantic Path Length**: Most systems have a path limit around 260 chars (Windows) or 4096 (Unix). Use a limit that works on all systems for testing. Use a limit that works on all systems for testing.
* **Semantic String Conversion**: For converting **one semantic string type to another**, you can use the pattern of converting to string first and then to the target type:
238
+
```csharp
239
+
// Example: Converting from one semantic string type to another
240
+
var sourceSemanticString = "example".As<SourceType>();
241
+
var targetSemanticString = sourceSemanticString.ToString().As<TargetType>();
242
+
243
+
// Or using implicit conversion to string:
244
+
var targetSemanticString = ((string)sourceSemanticString).As<TargetType>();
245
+
```
246
+
* **SemanticStringExtensions Class**: The `SemanticStringExtensions` class provides three main extension methods:
247
+
1. **`As<TDerived>(this string? value)`** - Converts a string to any semantic string type
248
+
2. **`As<TDerived>(this char[]? value)`** - Converts a character array to any semantic string type
249
+
3. **`As<TDerived>(this ReadOnlySpan<char> value)`** - Converts a read-only character span to any semantic string type
* **Redundant Interface Conversions**: The interface conversion methods like `AsAbsoluteDirectoryPath()` are redundant given the consolidated `As*()` API and direct casting, and should be removed.
0 commit comments