-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
general refactoring around the C# code
- Loading branch information
1 parent
603680c
commit 597022a
Showing
10 changed files
with
88 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using System; | ||
|
||
namespace SqlcGenCsharp; | ||
namespace SqlcGenCsharp.Drivers; | ||
|
||
public enum ClassMember | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,51 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using Enum = System.Enum; | ||
|
||
namespace SqlcGenCsharp; | ||
|
||
public enum RubyVersion | ||
{ | ||
Ruby1, | ||
Ruby2, | ||
Ruby3 | ||
V31, | ||
V32, | ||
V33 | ||
} | ||
|
||
public static class DotnetFrameworkExtensions | ||
public static partial class RubyVersionExtensions | ||
{ | ||
private static readonly Dictionary<RubyVersion, string> EnumToString = new() | ||
public static RubyVersion ParseName(string versionPattern) | ||
{ | ||
{ RubyVersion.Ruby1, "ruby1.0" }, | ||
{ RubyVersion.Ruby2, "ruby2.7" }, | ||
{ RubyVersion.Ruby3, "ruby3.3" } | ||
}; | ||
var semanticVersionRegex = SemanticVersionRegex(); | ||
var match = semanticVersionRegex.Match(versionPattern); | ||
if (!match.Success) | ||
throw new ArgumentException($"version {versionPattern} can't be parsed to a ruby version"); | ||
|
||
public static string ToName(this RubyVersion me) | ||
{ | ||
return EnumToString[me]; | ||
} | ||
var major = short.Parse(match.Groups[1].Value); | ||
if (major != 3) | ||
throw new ArgumentException($"Ruby versions older than Ruby3 are not supported"); | ||
|
||
public static RubyVersion ParseName(string dotnetFramework) | ||
{ | ||
return EnumToString | ||
.ToDictionary(x => x.Value, x => x.Key) | ||
[dotnetFramework]; | ||
short? minor = null; | ||
if (match.Groups[2].Success) | ||
minor = short.Parse(match.Groups[2].Value); | ||
if ((minor is < 1 or > 3)) | ||
throw new ArgumentException($"Ruby versions newer than Ruby3.3 do not exist"); | ||
|
||
// short? patch = null; patch version is currently not interesting | ||
// if (match.Groups[3].Success) | ||
// patch = short.Parse(match.Groups[3].Value); | ||
|
||
var rubyVersionStr = $"V{major}.{minor}"; | ||
var valid = Enum.TryParse(rubyVersionStr, out RubyVersion rubyVersion); | ||
if (!valid) | ||
throw new ArgumentException($"Failed to parse {rubyVersionStr} to {nameof(RubyVersion)}"); | ||
return rubyVersion; | ||
} | ||
|
||
public static bool LatestRubySupported(this RubyVersion me) | ||
{ | ||
return me == RubyVersion.Ruby3; | ||
return me is RubyVersion.V32 or RubyVersion.V33; | ||
} | ||
|
||
[GeneratedRegex(@"^(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*))?(?:\.(0|[1-9][0-9]*))?$")] | ||
private static partial Regex SemanticVersionRegex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters