Skip to content

Commit 3645220

Browse files
committed
Use RegexGenerator in .NET 7.
Update Conformance.Tests and MySqlConnector.Tests to target net7.0.
1 parent 3d822a3 commit 3645220

File tree

8 files changed

+34
-26
lines changed

8 files changed

+34
-26
lines changed

.ci/build-steps.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ steps:
2626
displayName: 'Publish MySqlConnector.Tests'
2727
inputs:
2828
command: 'publish'
29-
arguments: '-c Release -f net6.0 --no-build tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj'
29+
arguments: '-c Release -f net7.0 --no-build tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj'
3030
publishWebProjects: false
3131
zipAfterPublish: false
3232
- task: PublishPipelineArtifact@0
3333
inputs:
34-
artifactName: 'MySqlConnector.Tests-6.0-$(Agent.OS)'
35-
targetPath: 'tests/MySqlConnector.Tests/bin/Release/net6.0/publish'
34+
artifactName: 'MySqlConnector.Tests-7.0-$(Agent.OS)'
35+
targetPath: 'tests/MySqlConnector.Tests/bin/Release/net7.0/publish'
3636

3737
- task: DotNetCoreCLI@2
3838
displayName: 'Publish Conformance.Tests'
3939
inputs:
4040
command: 'publish'
41-
arguments: '-c Release -f net6.0 --no-build tests/Conformance.Tests/Conformance.Tests.csproj'
41+
arguments: '-c Release -f net7.0 --no-build tests/Conformance.Tests/Conformance.Tests.csproj'
4242
publishWebProjects: false
4343
zipAfterPublish: false
4444
- task: PublishPipelineArtifact@0
4545
inputs:
46-
artifactName: 'Conformance.Tests-6.0-$(Agent.OS)'
47-
targetPath: 'tests/Conformance.Tests/bin/Release/net6.0/publish'
46+
artifactName: 'Conformance.Tests-7.0-$(Agent.OS)'
47+
targetPath: 'tests/Conformance.Tests/bin/Release/net7.0/publish'
4848

4949
- task: DotNetCoreCLI@2
5050
displayName: 'Publish SideBySide (3.1)'

.ci/conformance-test-steps.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ steps:
1010
- task: DownloadPipelineArtifact@0
1111
condition: always()
1212
inputs:
13-
artifactName: 'Conformance.Tests-6.0-$(Agent.OS)'
14-
targetPath: '$(Build.BinariesDirectory)/6.0'
13+
artifactName: 'Conformance.Tests-7.0-$(Agent.OS)'
14+
targetPath: '$(Build.BinariesDirectory)/7.0'
1515
- task: DotNetCoreCLI@2
1616
displayName: 'Conformance Tests'
1717
inputs:
1818
command: 'custom'
1919
custom: 'vstest'
20-
arguments: '$(Build.BinariesDirectory)/6.0/Conformance.Tests.dll /logger:trx'
20+
arguments: '$(Build.BinariesDirectory)/7.0/Conformance.Tests.dll /logger:trx'
2121
env:
2222
CONNECTION_STRING: ${{ parameters.connectionString }}
2323
- task: PublishTestResults@2

.ci/mysqlconnector-tests-steps.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
steps:
2-
- task: UseDotNet@2
3-
displayName: 'Install .NET Core'
4-
inputs:
5-
version: 6.0.x
6-
packageType: runtime
72
- task: UseDotNet@2
83
displayName: 'Install .NET Core'
94
inputs:
105
version: $(DotNetCoreSdkVersion)
116
- task: DownloadPipelineArtifact@0
127
inputs:
13-
artifactName: 'MySqlConnector.Tests-6.0-$(Agent.OS)'
8+
artifactName: 'MySqlConnector.Tests-7.0-$(Agent.OS)'
149
targetPath: $(System.DefaultWorkingDirectory)
1510
- task: DotNetCoreCLI@2
1611
displayName: 'Run MySqlConnector.Tests'
@@ -22,4 +17,4 @@ steps:
2217
inputs:
2318
testResultsFormat: VSTest
2419
testResultsFiles: '**/*.trx'
25-
testRunTitle: 'MySqlConnector.Tests-6.0-$(Agent.OS)'
20+
testRunTitle: 'MySqlConnector.Tests-7.0-$(Agent.OS)'

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ dotnet_diagnostic.SA1503.severity = none # Braces should not be omitted.
105105
dotnet_diagnostic.SA1513.severity = none # Closing brace should be followed by blank line.
106106
dotnet_diagnostic.SA1516.severity = none # Elements should be separated by blank line.
107107
dotnet_diagnostic.SA1600.severity = none # Elements should be documented.
108+
dotnet_diagnostic.SA1601.severity = none # Partial elements should be documented.
108109
dotnet_diagnostic.SA1602.severity = none # Enumeration items should be documented.
109110
dotnet_diagnostic.SA1611.severity = none # Element parameters should be documented.
110111
dotnet_diagnostic.SA1615.severity = none # Element return value should be documented.

src/MySqlConnector/Core/NormalizedSchema.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
namespace MySqlConnector.Core;
44

5-
internal sealed class NormalizedSchema
5+
internal sealed partial class NormalizedSchema
66
{
77
private const string ReQuoted = @"`((?:[^`]|``)+)`";
88
private const string ReUnQuoted = @"([^\.`]+)";
99
private const string ReEither = $@"(?:{ReQuoted}|{ReUnQuoted})";
10+
private const string ReName = $@"^\s*{ReEither}\s*(?:\.\s*{ReEither}\s*)?$";
1011

11-
private static readonly Regex NameRe = new(
12-
$@"^\s*{ReEither}\s*(?:\.\s*{ReEither}\s*)?$",
13-
RegexOptions.Compiled);
12+
#if NET7_0_OR_GREATER
13+
[RegexGenerator(ReName)]
14+
private static partial Regex NameRegex();
15+
#else
16+
private static Regex NameRegex() => s_nameRegex;
17+
private static readonly Regex s_nameRegex = new(ReName, RegexOptions.Compiled);
18+
#endif
1419

1520
public static NormalizedSchema MustNormalize(string name, string? defaultSchema = null)
1621
{
@@ -24,7 +29,7 @@ public static NormalizedSchema MustNormalize(string name, string? defaultSchema
2429

2530
public NormalizedSchema(string name, string? defaultSchema = null)
2631
{
27-
var match = NameRe.Match(name);
32+
var match = NameRegex().Match(name);
2833
if (match.Success)
2934
{
3035
if (match.Groups[3].Success)

src/MySqlConnector/MySqlConnectionStringBuilder.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ protected override void GetProperties(Hashtable propertyDescriptors)
874874
private string? m_cachedConnectionStringWithoutPassword;
875875
}
876876

877-
internal abstract class MySqlConnectionStringOption
877+
internal abstract partial class MySqlConnectionStringOption
878878
{
879879
// Connection Options
880880
public static readonly MySqlConnectionStringReferenceOption<string> Server;
@@ -1045,7 +1045,7 @@ static MySqlConnectionStringOption()
10451045
Span<bool> versions = stackalloc bool[4];
10461046
foreach (var part in value!.TrimStart('[', '(').TrimEnd(')', ']').Split(','))
10471047
{
1048-
var match = s_tlsVersions.Match(part);
1048+
var match = TlsVersionsRegex().Match(part);
10491049
if (!match.Success)
10501050
throw new ArgumentException($"Unrecognized TlsVersion protocol version '{part}'; permitted versions are: TLS 1.0, TLS 1.1, TLS 1.2, TLS 1.3.");
10511051
var version = match.Groups[2].Value;
@@ -1233,7 +1233,14 @@ static MySqlConnectionStringOption()
12331233
defaultValue: true));
12341234
}
12351235

1236-
private static readonly Regex s_tlsVersions = new(@"\s*TLS( ?v?(1|1\.?0|1\.?1|1\.?2|1\.?3))?$", RegexOptions.IgnoreCase);
1236+
private const string c_tlsVersionsRegexPattern = @"\s*TLS( ?v?(1|1\.?0|1\.?1|1\.?2|1\.?3))?$";
1237+
#if NET7_0_OR_GREATER
1238+
[RegexGenerator(c_tlsVersionsRegexPattern, RegexOptions.IgnoreCase)]
1239+
private static partial Regex TlsVersionsRegex();
1240+
#else
1241+
private static Regex TlsVersionsRegex() => s_tlsVersionsRegex;
1242+
private static readonly Regex s_tlsVersionsRegex = new(c_tlsVersionsRegexPattern, RegexOptions.IgnoreCase);
1243+
#endif
12371244
private static readonly Dictionary<string, MySqlConnectionStringOption> s_options;
12381245

12391246
private readonly IReadOnlyList<string> m_keys;

tests/Conformance.Tests/Conformance.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0</TargetFrameworks>
4+
<TargetFrameworks>net7.0</TargetFrameworks>
55
<VersionPrefix>0.1.0</VersionPrefix>
66
<SignAssembly>true</SignAssembly>
77
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>

tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup Condition=" '$(Configuration)' != 'Baseline' ">
4-
<TargetFrameworks>net6.0</TargetFrameworks>
4+
<TargetFrameworks>net7.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<PropertyGroup Condition=" '$(Configuration)' == 'Baseline' ">

0 commit comments

Comments
 (0)