Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor Regex initialization with conditional compilation.
Reorganized Regex initialization using `#if NET8_0_OR_GREATER` to leverage `GeneratedRegex` for .NET 8+ and fallback to static initialization otherwise instance is null.
  • Loading branch information
khalidabuhakmeh committed May 2, 2025
commit 7aee95ecfdffbe1d3bf3da3ca4fe53eae00ee857
12 changes: 6 additions & 6 deletions src/MarkdownSnippets/Reading/ExpressiveCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
internal partial class ExpressiveCode
{
#if NET8_0_OR_GREATER
[GeneratedRegex(@"([a-zA-Z0-9\-_]+)(?:\((.*?)\))?")]
protected partial Regex KeyPatternRegex();
#else
protected static readonly Regex KeyPatternRegex = new(@"([a-zA-Z0-9\-_]+)(?:\((.*?)\))?");
#endif
public ExpressiveCode() =>
#if NET8_0_OR_GREATER
Pattern = KeyPatternRegex();
Expand All @@ -8,10 +14,4 @@ public ExpressiveCode() =>
#endif
public static ExpressiveCode Instance { get; } = new();
public Regex Pattern { get; }
#if NET8_0_OR_GREATER
[GeneratedRegex(@"([a-zA-Z0-9\-_]+)(?:\((.*?)\))?")]
protected partial Regex KeyPatternRegex();
#else
protected static readonly Regex KeyPatternRegex = new(@"([a-zA-Z0-9\-_]+)(?:\((.*?)\))?");
#endif
}