Upgrade to C# 14 and modernize codebase #204
Merged
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.
Description
This PR upgrades the project from C# 10 to C# 14 and systematically modernizes the codebase by adopting the latest C# language features where there's the greatest immediate benefit. The changes are purely syntactic and do not alter the runtime behavior of the library.
Overview
The modernization effort focuses on improving code readability and maintainability by leveraging C# language enhancements since version 10. All examples, source code, and tests have been updated to use modern C# idioms while maintaining backward compatibility at the API level.
Key Changes
Language Version Update
LangVersionfrom 10 to 14 inDirectory.Build.propsto enable all modern C# featuresRaw String Literals (C# 11)
@"...") with raw string literals ("""...""") throughout the codebaseCollection Expressions (C# 12)
[])new[] { ... }with[...]for more concise array declarationsArray.Empty<T>()→[])Primary Constructors (C# 12)
#pragma warning disable IDE0290in cases where protected constructors cannot use primary syntaxExtension Types/Members (C# 14)
extension(Type)syntaxParseResultExtensions,ApplicationResultExtensions, and various helper methodsPattern Matching Enhancements
StartsWith/EndsWithchecks with list patterns (e.g.,['-', '-', ..]for strings starting with "--")if-elsechains toswitchexpressions with pattern matchingString Manipulation
Substringcalls with range syntax ([i..],[..i],[i..j])With Expressions
withexpressions for record-like updates (e.g., updating node values)Field-Backed Properties
Type Pattern Refinements
is T ? T : default) with pattern expressions (as T)Syntactic Cleanup
;for empty interfaces)Testing
All existing tests pass without modification to their logic. The changes are purely syntactic: