Skip to content

Commit

Permalink
Update nullable annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel Nobel committed May 3, 2023
1 parent a48d576 commit abb3438
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/Qowaiv/Identifiers/Id.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ void IXmlSerializable.WriteXml(XmlWriter writer)
/// </exception>
[Pure]
public static Id<TIdentifier> Parse(string? s)
{
return TryParse(s, out Id<TIdentifier> val)
? val
: throw new FormatException();
}
=> TryParse(s, out Id<TIdentifier> val)
? val
: throw new FormatException();

/// <summary>Converts the <see cref="string"/> to <see cref="Id{TIdentifier}"/>.</summary>
/// <param name="s">
Expand All @@ -253,9 +251,7 @@ public static Id<TIdentifier> Parse(string? s)
/// </returns>
[Pure]
public static Id<TIdentifier> TryParse(string? s)
{
return TryParse(s, out Id<TIdentifier> val) ? val : default;
}
=> 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.
Expand Down Expand Up @@ -308,11 +304,9 @@ public static bool TryParse(string? s, out Id<TIdentifier> result)
/// </param>
[Pure]
public static Id<TIdentifier> FromBytes(byte[]? bytes)
{
return bytes is null || bytes.Length == 0
? Empty
: new Id<TIdentifier>(behavior.FromBytes(bytes));
}
=> bytes is null || bytes.Length == 0
? Empty
: new Id<TIdentifier>(behavior.FromBytes(bytes));

/// <summary>Creates an identifier from an <see cref="object"/>.</summary>
/// <param name="obj">
Expand All @@ -322,7 +316,7 @@ public static Id<TIdentifier> FromBytes(byte[]? bytes)
/// if the identifier could not be created from the <see cref="object"/>.
/// </exception>
[Pure]
public static Id<TIdentifier> Create(object obj)
public static Id<TIdentifier> Create(object? obj)
=> TryCreate(obj, out var id)
? id
: throw Exceptions.InvalidCast(obj?.GetType(), typeof(Id<TIdentifier>));
Expand All @@ -337,7 +331,7 @@ public static Id<TIdentifier> Create(object obj)
/// <returns>
/// True if the identifier could be created.
/// </returns>
public static bool TryCreate(object obj, out Id<TIdentifier> id)
public static bool TryCreate(object? obj, out Id<TIdentifier> id)
{
id = default;

Expand All @@ -362,5 +356,5 @@ public static bool TryCreate(object obj, out Id<TIdentifier> id)
/// The <see cref="string"/> to validate.
/// </param>
[Pure]
public static bool IsValid(string val) => !string.IsNullOrWhiteSpace(val) && TryParse(val, out _);
public static bool IsValid(string? val) => !string.IsNullOrWhiteSpace(val) && TryParse(val, out _);
}

0 comments on commit abb3438

Please sign in to comment.