You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ Improve nullable annotations for net7.0 multi-targeting (#1175)
Inspired by article: https://www.meziantou.net/how-to-use-nullable-reference-types-in-dotnet-standard-2-0-and-dotnet-.htm
Related to #1164
### Changes
- Add `NullableAttributes.cs` via `Directory.Build.props` to shim annotation attributes for netstandard2.0 and older .NET versions
- Fix nullable warnings, observed when multitargeting net7.0 + netstandard2.0
- Add `[NotNullWhen(true)]` to all `Try` methods
- Remove redundant `!` nullable suppressions
/// <summary>Indicates strict equality of two <see cref=""{_quantity.Name}""/> quantities, where both <see cref=""Value"" /> and <see cref=""Unit"" /> are exactly equal.</summary>
762
763
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, {_valueType}, ComparisonType)""/> to check equality across different units and to specify a floating-point number error tolerance.</remarks>
763
764
[Obsolete(""Consider using Equals(Angle, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")]
764
-
public override bool Equals(object obj)
765
+
public override bool Equals(object? obj)
765
766
{{
766
767
if (obj is null || !(obj is {_quantity.Name} otherQuantity))
767
768
return false;
@@ -793,7 +794,7 @@ public bool Equals({_quantity.Name} other)
793
794
/// <item><term> Greater than zero</term><description> This instance follows <paramref name=""obj"" /> in the sort order.</description></item>
794
795
/// </list>
795
796
/// </returns>
796
-
public int CompareTo(object obj)
797
+
public int CompareTo(object? obj)
797
798
{{
798
799
if (obj is null) throw new ArgumentNullException(nameof(obj));
799
800
if (!(obj is {_quantity.Name} otherQuantity)) throw new ArgumentException(""Expected type {_quantity.Name}."", nameof(obj));
@@ -1116,7 +1124,7 @@ public string ToString(string format)
1116
1124
/// <param name=""format"">The format string.</param>
1117
1125
/// <param name=""provider"">Format to use for localization and number formatting. Defaults to <see cref=""CultureInfo.CurrentCulture"" /> if null.</param>
1118
1126
/// <returns>The string representation.</returns>
1119
-
public string ToString(string format, IFormatProvider? provider)
1127
+
public string ToString(string? format, IFormatProvider? provider)
1120
1128
{{
1121
1129
return QuantityFormatter.Format<{_unitEnumName}>(this, format, provider);
1122
1130
}}
@@ -1127,75 +1135,75 @@ public string ToString(string format, IFormatProvider? provider)
0 commit comments