Skip to content

Commit

Permalink
chore: change IParsable<T> to explicit impl. as IFormatProvider is no…
Browse files Browse the repository at this point in the history
…t of any use to us. Additionally, change visibility of the new static Parse/TryParse methods to internal for time being, until we are ready for v6. Otherwise, the difference in behavior to IbanParser can lead to confusion.
  • Loading branch information
skwasjer committed Jul 15, 2023
1 parent 1405e32 commit aeafc7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## Unreleased

- [#138](https://github.com/skwasjer/IbanNet/pull/138) Implement `IParsable<TSelf>` on Iban type.

## v5.10.0

- Upgraded SWIFT registry provider to July '23 release 95, which adds Falkland Islands (FK).
- Upgraded Wikipedia registry provider, which adds North Macedonia (MK).
- [#144](https://github.com/skwasjer/IbanNet/pull/144) Add Catalan localization.
- [#138](https://github.com/skwasjer/IbanNet/pull/138) Implement `IParsable<TSelf>` on Iban type.
- In `IbanParser` internals, use `ReadOnlySpan<T>`.
- Add additional constructor overloads to `IbanValidator`, in preparation of possible deprecation of `IbanValidatorOptions`. Even if not deprecating, it is still convenient.

Expand Down
34 changes: 18 additions & 16 deletions src/IbanNet/Iban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ public override int GetHashCode()
/// <returns>An <see cref="Iban" /> if the <paramref name="s" /> is converted successfully.</returns>
/// <exception cref="ArgumentNullException">Thrown when the specified <paramref name="s" /> is <see langword="null" />.</exception>
/// <exception cref="IbanFormatException">Thrown when the specified <paramref name="s" /> is not a valid IBAN.</exception>
public static Iban Parse(string s) => Parse(s, null);
internal static Iban Parse(string s)
{
var parser = new IbanParser(IbanRegistry.Default);
return parser.Parse(s);
}

#if NET7_0_OR_GREATER
/// <summary>
/// Converts the specified <paramref name="s" /> into an <see cref="Iban" />.
/// </summary>
Expand All @@ -296,34 +301,31 @@ public override int GetHashCode()
/// <returns>An <see cref="Iban" /> if the <paramref name="s" /> is converted successfully.</returns>
/// <exception cref="ArgumentNullException">Thrown when the specified <paramref name="s" /> is <see langword="null" />.</exception>
/// <exception cref="IbanFormatException">Thrown when the specified <paramref name="s" /> is not a valid IBAN.</exception>
#pragma warning disable IDE0060
public static Iban Parse(string s, IFormatProvider? provider)
#pragma warning restore IDE0060
{
var parser = new IbanParser(IbanRegistry.Default);
return parser.Parse(s);
}
static Iban IParsable<Iban>.Parse(string s, IFormatProvider? provider)
=> Parse(s);
#endif

/// <summary>
/// Tries to convert the specified <paramref name="s" /> into an <see cref="Iban" />.
/// </summary>
/// <param name="s">The IBAN value to parse.</param>
/// <param name="result">The <see cref="Iban" /> if the <paramref name="s" /> is converted successfully.</param>
/// <returns><see langword="true" /> if the <paramref name="s" /> is converted successfully, or <see langword="false" /> otherwise</returns>
public static bool TryParse(string? s, [NotNullWhen(true)] out Iban? result) => TryParse(s, null, out result);
internal static bool TryParse(string? s, [NotNullWhen(true)] out Iban? result)
{
var parser = new IbanParser(IbanRegistry.Default);
return parser.TryParse(s, out result);
}

#if NET7_0_OR_GREATER
/// <summary>
/// Tries to convert the specified <paramref name="s" /> into an <see cref="Iban" />.
/// </summary>
/// <param name="s">The IBAN value to parse.</param>
/// <param name="provider">An object that supplies culture-specific formatting information about <paramref name="s" />.</param>
/// <param name="result">The <see cref="Iban" /> if the <paramref name="s" /> is converted successfully.</param>
/// <returns><see langword="true" /> if the <paramref name="s" /> is converted successfully, or <see langword="false" /> otherwise</returns>
#pragma warning disable IDE0060
public static bool TryParse(string? s, IFormatProvider? provider, [NotNullWhen(true)] out Iban? result)
#pragma warning restore IDE0060
{
var parser = new IbanParser(IbanRegistry.Default);
return parser.TryParse(s, out result);
}
static bool IParsable<Iban>.TryParse(string? s, IFormatProvider? provider, [NotNullWhen(true)] out Iban? result)
=> TryParse(s, out result);
#endif
}

0 comments on commit aeafc7e

Please sign in to comment.