Skip to content

Commit

Permalink
Implement IParsable for Id<TIdBehavior> (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Jan 29, 2024
1 parent bf384e5 commit 3d510e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 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
37 changes: 37 additions & 0 deletions src/Qowaiv/Identifiers/Id.cs
Expand Up @@ -21,6 +21,7 @@ namespace Qowaiv.Identifiers;
public readonly struct Id<TIdentifier> : IXmlSerializable, IFormattable, IEquatable<Id<TIdentifier>>, IComparable, IComparable<Id<TIdentifier>>
#if NET7_0_OR_GREATER
, IEqualityOperators<Id<TIdentifier>, Id<TIdentifier>, bool>
, IParsable<Id<TIdentifier>>
#endif
#if NET8_0_OR_GREATER
#else
Expand Down Expand Up @@ -240,6 +241,24 @@ void IXmlSerializable.WriteXml(XmlWriter writer)
/// <summary>Casts the <see cref="Uuid"/> to an identifier.</summary>
public static explicit operator Id<TIdentifier>(Uuid id) => Create(id);

/// <summary>Converts the <see cref="string"/> to <see cref="Id{TIdentifier}"/>.</summary>
/// <param name="s">
/// A string containing the identifier to convert.
/// </param>
/// <param name="provider">
/// The format provider.
/// </param>
/// <returns>
/// <returns>
/// The parsed identifier.
/// </returns>
/// <exception cref="FormatException">
/// <paramref name="s"/> is not in the correct format.
/// </exception>
[Pure]

Check warning on line 258 in src/Qowaiv/Identifiers/Id.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 258 in src/Qowaiv/Identifiers/Id.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 258 in src/Qowaiv/Identifiers/Id.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'
public static Id<TIdentifier> Parse(string s, IFormatProvider? provider)
=> Parse(s);

/// <summary>Converts the <see cref="string"/> to <see cref="Id{TIdentifier}"/>.</summary>
/// <param name="s">
/// A string containing the identifier to convert.
Expand Down Expand Up @@ -269,6 +288,24 @@ public static Id<TIdentifier> TryParse(string? s)
return TryParse(s, out Id<TIdentifier> val) ? val : default;
}

/// <summary>Converts the <see cref="string"/> to <see cref = "Id{TIdentifier}"/>.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="s">
/// A string containing the identifier to convert.
/// </param>
/// <param name="provider">
/// The format provider.
/// </param>
/// <param name="result">
/// The result of the parsing.
/// </param>
/// <returns>
/// True if the string was converted successfully, otherwise false.
/// </returns>
public static bool TryParse(string? s, IFormatProvider? provider, out Id<TIdentifier> result)
=> TryParse(s, out result);

/// <summary>Converts the <see cref="string"/> to <see cref = "Id{TIdentifier}"/>.
/// A return value indicates whether the conversion succeeded.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Qowaiv/Qowaiv.csproj
Expand Up @@ -8,6 +8,8 @@
<Version>6.6.0</Version>
<PackageId>Qowaiv</PackageId>
<PackageReleaseNotes>
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
Expand Down

0 comments on commit 3d510e4

Please sign in to comment.