Skip to content

Commit

Permalink
Fix Unity 2019.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Aug 18, 2023
1 parent 4449a82 commit d4d834f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
28 changes: 10 additions & 18 deletions src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ public override string ToString()
//
//ISpanFormattable
//
#nullable enable
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider)
{
if (TryWriteStringify(destination))
{
Expand All @@ -478,31 +477,28 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
}
}

public string ToString(string? format, IFormatProvider? formatProvider) => ToString();
#nullable disable
public string ToString(string format, IFormatProvider formatProvider) => ToString();
#endif

#if NET7_0_OR_GREATER
//
// IParsable
//
#nullable enable
/// <inheritdoc cref="IParsable{TSelf}.Parse(string, IFormatProvider?)" />
public static Ulid Parse(string s, IFormatProvider? provider) => Parse(s);
public static Ulid Parse(string s, IFormatProvider provider) => Parse(s);

/// <inheritdoc cref="IParsable{TSelf}.TryParse(string?, IFormatProvider?, out TSelf)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out Ulid result) => TryParse(s, out result);
public static bool TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out Ulid result) => TryParse(s, out result);

//
// ISpanParsable
//

/// <inheritdoc cref="ISpanParsable{TSelf}.Parse(ReadOnlySpan{char}, IFormatProvider?)" />
public static Ulid Parse(ReadOnlySpan<char> s, IFormatProvider? provider) => Parse(s);
public static Ulid Parse(ReadOnlySpan<char> s, IFormatProvider provider) => Parse(s);

/// <inheritdoc cref="ISpanParsable{TSelf}.TryParse(ReadOnlySpan{char}, IFormatProvider?, out TSelf)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Ulid result) => TryParse(s, out result);
#nullable disable
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out Ulid result) => TryParse(s, out result);
#endif

// Comparable/Equatable
Expand Down Expand Up @@ -573,24 +569,20 @@ public int CompareTo(Ulid other)
return 0;
}

#nullable enable
public int CompareTo(object? value)
public int CompareTo(object value)
{
if (value == null)
{
return 1;
}

if (value is not Ulid ulid)
if (value is Ulid ulid)
{
throw new ArgumentException("Object must be of type ULID.", nameof(value));
return this.CompareTo(ulid);
}

return this.CompareTo(ulid);
throw new ArgumentException("Object must be of type ULID.", nameof(value));
}

#nullable disable

public static explicit operator Guid(Ulid _this)
{
return _this.ToGuid();
Expand Down
28 changes: 10 additions & 18 deletions src/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ public override string ToString()
//
//ISpanFormattable
//
#nullable enable
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider)
{
if (TryWriteStringify(destination))
{
Expand All @@ -478,31 +477,28 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
}
}

public string ToString(string? format, IFormatProvider? formatProvider) => ToString();
#nullable disable
public string ToString(string format, IFormatProvider formatProvider) => ToString();
#endif

#if NET7_0_OR_GREATER
//
// IParsable
//
#nullable enable
/// <inheritdoc cref="IParsable{TSelf}.Parse(string, IFormatProvider?)" />
public static Ulid Parse(string s, IFormatProvider? provider) => Parse(s);
public static Ulid Parse(string s, IFormatProvider provider) => Parse(s);

/// <inheritdoc cref="IParsable{TSelf}.TryParse(string?, IFormatProvider?, out TSelf)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out Ulid result) => TryParse(s, out result);
public static bool TryParse([NotNullWhen(true)] string s, IFormatProvider provider, out Ulid result) => TryParse(s, out result);

//
// ISpanParsable
//

/// <inheritdoc cref="ISpanParsable{TSelf}.Parse(ReadOnlySpan{char}, IFormatProvider?)" />
public static Ulid Parse(ReadOnlySpan<char> s, IFormatProvider? provider) => Parse(s);
public static Ulid Parse(ReadOnlySpan<char> s, IFormatProvider provider) => Parse(s);

/// <inheritdoc cref="ISpanParsable{TSelf}.TryParse(ReadOnlySpan{char}, IFormatProvider?, out TSelf)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Ulid result) => TryParse(s, out result);
#nullable disable
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out Ulid result) => TryParse(s, out result);
#endif

// Comparable/Equatable
Expand Down Expand Up @@ -573,24 +569,20 @@ public int CompareTo(Ulid other)
return 0;
}

#nullable enable
public int CompareTo(object? value)
public int CompareTo(object value)
{
if (value == null)
{
return 1;
}

if (value is not Ulid ulid)
if (value is Ulid ulid)
{
throw new ArgumentException("Object must be of type ULID.", nameof(value));
return this.CompareTo(ulid);
}

return this.CompareTo(ulid);
throw new ArgumentException("Object must be of type ULID.", nameof(value));
}

#nullable disable

public static explicit operator Guid(Ulid _this)
{
return _this.ToGuid();
Expand Down

0 comments on commit d4d834f

Please sign in to comment.