From 3d510e4600eea1aa7c7c652e1babec4c5319d732 Mon Sep 17 00:00:00 2001 From: Corniel Nobel Date: Mon, 29 Jan 2024 10:35:03 +0100 Subject: [PATCH] Implement IParsable for Id (#372) --- specs/Qowaiv.Specs/Identifiers/Id_specs.cs | 15 +++++++++ src/Qowaiv/Identifiers/Id.cs | 37 ++++++++++++++++++++++ src/Qowaiv/Qowaiv.csproj | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 specs/Qowaiv.Specs/Identifiers/Id_specs.cs diff --git a/specs/Qowaiv.Specs/Identifiers/Id_specs.cs b/specs/Qowaiv.Specs/Identifiers/Id_specs.cs new file mode 100644 index 00000000..76074e47 --- /dev/null +++ b/specs/Qowaiv.Specs/Identifiers/Id_specs.cs @@ -0,0 +1,15 @@ +#if NET8_0_OR_GREATER + +namespace Identifiers.Id_specs; + +public class Can_parse +{ + [Test] + public void providing_a_format_provider() + { + CustomGuid.Parse("8A1A8C42-D2FF-E254-E26E-B6ABCBF19420", TestCultures.pt).Should().Be(Svo.CustomGuid); + CustomGuid.TryParse("8A1A8C42-D2FF-E254-E26E-B6ABCBF19420", TestCultures.pt, out _).Should().BeTrue(); + } +} + +#endif diff --git a/src/Qowaiv/Identifiers/Id.cs b/src/Qowaiv/Identifiers/Id.cs index 4c8c0611..84182eb8 100644 --- a/src/Qowaiv/Identifiers/Id.cs +++ b/src/Qowaiv/Identifiers/Id.cs @@ -21,6 +21,7 @@ namespace Qowaiv.Identifiers; public readonly struct Id : IXmlSerializable, IFormattable, IEquatable>, IComparable, IComparable> #if NET7_0_OR_GREATER , IEqualityOperators, Id, bool> +, IParsable> #endif #if NET8_0_OR_GREATER #else @@ -240,6 +241,24 @@ void IXmlSerializable.WriteXml(XmlWriter writer) /// Casts the to an identifier. public static explicit operator Id(Uuid id) => Create(id); + /// Converts the to . + /// + /// A string containing the identifier to convert. + /// + /// + /// The format provider. + /// + /// + /// + /// The parsed identifier. + /// + /// + /// is not in the correct format. + /// + [Pure] + public static Id Parse(string s, IFormatProvider? provider) + => Parse(s); + /// Converts the to . /// /// A string containing the identifier to convert. @@ -269,6 +288,24 @@ public static Id TryParse(string? s) return TryParse(s, out Id val) ? val : default; } + /// Converts the to . + /// A return value indicates whether the conversion succeeded. + /// + /// + /// A string containing the identifier to convert. + /// + /// + /// The format provider. + /// + /// + /// The result of the parsing. + /// + /// + /// True if the string was converted successfully, otherwise false. + /// + public static bool TryParse(string? s, IFormatProvider? provider, out Id result) + => TryParse(s, out result); + /// Converts the to . /// A return value indicates whether the conversion succeeded. /// diff --git a/src/Qowaiv/Qowaiv.csproj b/src/Qowaiv/Qowaiv.csproj index 07146ee7..07c10365 100644 --- a/src/Qowaiv/Qowaiv.csproj +++ b/src/Qowaiv/Qowaiv.csproj @@ -8,6 +8,8 @@ 6.6.0 Qowaiv +v6.6.1 +- Add missing IParsable interface for Id. #372 v6.6.0 - Add former countries. #357 - Update display names countries (EN, DE, NL). #356