Skip to content

Commit

Permalink
Better source generation
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Dec 8, 2023
1 parent e3aa9ba commit 170d2a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
33 changes: 2 additions & 31 deletions src/Credfeto.ChangeLog/Helpers/SourceGenerated.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
using System.Text.RegularExpressions;

namespace Credfeto.ChangeLog.Helpers;

#if NET6_0
internal static class SourceGenerated
{
public static Regex RemoveCommentsRegex()
{
return new(pattern: RegexSettings.RemoveCommentsRegex, options: RegexSettings.RemoveCommentsOptions, matchTimeout: Net6Compat.Short);
}

public static Regex VersionHeaderRegex()
{
return new(pattern: RegexSettings.VersionHeaderRegex, options: RegexSettings.VersionHeaderOptions, matchTimeout: Net6Compat.Short);
}

public static Regex GitHunkPositionRegex()
{
return new(pattern: RegexSettings.GitHunkPositionRegex, options: RegexSettings.GitHunkPositionOptions, matchTimeout: Net6Compat.Short);
}
}
#else
internal static partial class SourceGenerated
{
[GeneratedRegex(pattern: RegexSettings.RemoveCommentsRegex, options: RegexSettings.RemoveCommentsOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex RemoveCommentsRegex();

[GeneratedRegex(pattern: RegexSettings.VersionHeaderRegex, options: RegexSettings.VersionHeaderOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex VersionHeaderRegex();

[GeneratedRegex(pattern: RegexSettings.GitHunkPositionRegex, options: RegexSettings.GitHunkPositionOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex GitHunkPositionRegex();
}
#endif
// source generated code
}
29 changes: 29 additions & 0 deletions src/Credfeto.ChangeLog/Helpers/SourceGenerated.net6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if NET7_0_OR_GREATER
#else

using System.Text.RegularExpressions;

namespace Credfeto.ChangeLog.Helpers;

internal static partial class SourceGenerated
{
private static readonly Regex RegexRemoveComments = new(pattern: RegexSettings.RemoveCommentsRegex, options: RegexSettings.RemoveCommentsOptions, matchTimeout: Net6Compat.Short);
private static readonly Regex RegexVersionHeader = new(pattern: RegexSettings.VersionHeaderRegex, options: RegexSettings.VersionHeaderOptions, matchTimeout: Net6Compat.Short);
private static readonly Regex RegexGitHunkPosition = new(pattern: RegexSettings.GitHunkPositionRegex, options: RegexSettings.GitHunkPositionOptions, matchTimeout: Net6Compat.Short);

public static Regex RemoveCommentsRegex()
{
return RegexRemoveComments;
}

public static Regex VersionHeaderRegex()
{
return RegexVersionHeader;
}

public static Regex GitHunkPositionRegex()
{
return RegexGitHunkPosition;
}
}
#endif
17 changes: 17 additions & 0 deletions src/Credfeto.ChangeLog/Helpers/SourceGenerated.net7.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if NET7_0_OR_GREATER
using System.Text.RegularExpressions;

namespace Credfeto.ChangeLog.Helpers;

internal static partial class SourceGenerated
{
[GeneratedRegex(pattern: RegexSettings.RemoveCommentsRegex, options: RegexSettings.RemoveCommentsOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex RemoveCommentsRegex();

[GeneratedRegex(pattern: RegexSettings.VersionHeaderRegex, options: RegexSettings.VersionHeaderOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex VersionHeaderRegex();

[GeneratedRegex(pattern: RegexSettings.GitHunkPositionRegex, options: RegexSettings.GitHunkPositionOptions, matchTimeoutMilliseconds: RegexSettings.TimeoutMilliseconds)]
public static partial Regex GitHunkPositionRegex();
}
#endif

0 comments on commit 170d2a0

Please sign in to comment.