Skip to content

Migrate TagExpressions to source-generated regexes (multi-target netstandard2.0 + net8.0)#14

Merged
kzu merged 3 commits intomasterfrom
copilot/migrate-to-source-generated-regex
Mar 29, 2026
Merged

Migrate TagExpressions to source-generated regexes (multi-target netstandard2.0 + net8.0)#14
kzu merged 3 commits intomasterfrom
copilot/migrate-to-source-generated-regex

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Replaces the static Regex fields and static constructor in TagExpressions.cs with source-generated regexes on net8.0+, while retaining compiled Regex fallbacks for netstandard2.0.

TagExpressions.cs

  • Made partial
  • #if NET8_0_OR_GREATER: [GeneratedRegex]-decorated static partial methods (compile-time generated, zero-allocation)
  • #else: static readonly Regex fields with RegexOptions.Compiled exposed through matching static Regex Foo() methods — identical call-site signature across both targets
#if NET8_0_OR_GREATER
    [GeneratedRegex(@"<[^\s>]*\b(name|value-of)\b[^>]*/>")]
    public static partial Regex NameValueOf();
#else
    static readonly Regex _nameValueOf = new Regex(@"<[^\s>]*\b(name|value-of)\b[^>]*/>", RegexOptions.Compiled);
    public static Regex NameValueOf() => _nameValueOf;
#endif

The AllSchematron pattern hardcodes the Regex.Escape-d values of Schema.LegacyNamespace / Schema.IsoNamespace (required since [GeneratedRegex] demands a compile-time constant); a comment flags the dependency.

Schematron.csproj

  • TargetFrameworkTargetFrameworks: netstandard2.0;net8.0
  • PolySharp restored, scoped to netstandard2.0 only (not needed on net8.0)

Call sites

All four call sites (LogFormatter, XmlFormatter, Config, Test) already use TagExpressions.Foo() method-call syntax from the initial migration step — no further changes needed.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI assigned Copilot and kzu Mar 29, 2026
Copilot AI linked an issue Mar 29, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Migrate from static regex to source-generated regexes Migrate TagExpressions to source-generated regexes (multi-target netstandard2.0 + net8.0) Mar 29, 2026
Copilot finished work on behalf of kzu March 29, 2026 21:40
Copilot AI requested a review from kzu March 29, 2026 21:40
@kzu kzu marked this pull request as ready for review March 29, 2026 21:44
@kzu kzu enabled auto-merge (rebase) March 29, 2026 21:45
@kzu
Copy link
Copy Markdown
Member

kzu commented Mar 29, 2026

49 passed 49 passed

🧪 Details on Ubuntu 24.04.4 LTS

from retest v1.1.0 on .NET 10.0.5 with 💜 by @devlooped

@kzu kzu merged commit 243f24c into master Mar 29, 2026
4 checks passed
@kzu kzu deleted the copilot/migrate-to-source-generated-regex branch March 29, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from static Regex to source-generated regexes

2 participants