diff --git a/Build/build-functions.psm1 b/Build/build-functions.psm1 index b4521037e3..3ba81899ca 100644 --- a/Build/build-functions.psm1 +++ b/Build/build-functions.psm1 @@ -7,7 +7,7 @@ $nuget = "$root\Tools\NuGet.exe" $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath if ($msbuild) { - $msbuild = join-path $msbuild 'MSBuild\15.0\Bin\MSBuild.exe' + $msbuild = join-path $msbuild 'MSBuild\Current\Bin\MSBuild.exe' } function Remove-ArtifactsDir { diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index caff760f4a..4d3942f9d5 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -51,6 +51,8 @@ public override string Generate() using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -186,7 +188,7 @@ private void GenerateInstanceConstructors() /// No unit was found for the given . public {_quantity.Name}({_valueType} value, UnitSystem unitSystem) {{ - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -338,7 +340,7 @@ public static string GetAbbreviation({_unitEnumName} unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation({_unitEnumName} unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation({_unitEnumName} unit, IFormatProvider? provider) {{ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); }} @@ -441,7 +443,7 @@ private void GenerateStaticParseMethods() /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static {_quantity.Name} Parse(string str, [CanBeNull] IFormatProvider provider) + public static {_quantity.Name} Parse(string str, IFormatProvider? provider) {{ return QuantityParser.Default.Parse<{_quantity.Name}, {_unitEnumName}>( str, @@ -457,7 +459,7 @@ private void GenerateStaticParseMethods() /// /// Length.Parse(""5.5 m"", new CultureInfo(""en-US"")); /// - public static bool TryParse([CanBeNull] string str, out {_quantity.Name} result) + public static bool TryParse(string? str, out {_quantity.Name} result) {{ return TryParse(str, null, out result); }} @@ -472,7 +474,7 @@ public static bool TryParse([CanBeNull] string str, out {_quantity.Name} result) /// Length.Parse(""5.5 m"", new CultureInfo(""en-US"")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out {_quantity.Name} result) + public static bool TryParse(string? str, IFormatProvider? provider, out {_quantity.Name} result) {{ return QuantityParser.Default.TryParse<{_quantity.Name}, {_unitEnumName}>( str, @@ -505,7 +507,7 @@ public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider /// /// The value of 'str' cannot be null. /// Error parsing string. - public static {_unitEnumName} ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static {_unitEnumName} ParseUnit(string str, IFormatProvider? provider) {{ return UnitParser.Default.Parse<{_unitEnumName}>(str, provider); }} @@ -526,7 +528,7 @@ public static bool TryParseUnit(string str, out {_unitEnumName} unit) /// Length.TryParseUnit(""m"", new CultureInfo(""en-US"")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out {_unitEnumName} unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out {_unitEnumName} unit) {{ return UnitParser.Default.TryParse<{_unitEnumName}>(str, provider, out unit); }} @@ -818,7 +820,7 @@ public double As({_unitEnumName} unit) /// public double As(UnitSystem unitSystem) {{ - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -861,7 +863,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public {_quantity.Name} ToUnit(UnitSystem unitSystem) {{ - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -960,7 +962,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) {{ return ToString(""g"", provider); }} @@ -972,7 +974,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@""This method is deprecated and will be removed at a future release. Please use ToString(""""s2"""") or ToString(""""s2"""", provider) where 2 is an example of the number passed to significantDigitsAfterRadix."")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) {{ var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -987,7 +989,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(""This method is deprecated and will be removed at a future release. Please use string.Format()."")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) {{ if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1015,15 +1017,15 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) {{ - return QuantityFormatter.Format<{_unitEnumName}>(this, format, formatProvider); + return QuantityFormatter.Format<{_unitEnumName}>(this, format, provider); }} #endregion -"); +" ); } private void GenerateIConvertibleMethods() diff --git a/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs index 25d9143e49..066543d2de 100644 --- a/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs @@ -22,6 +22,8 @@ public override string Generate() using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + namespace UnitsNet { /// @@ -60,7 +62,7 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu /// Unit enum value. /// The resulting quantity if successful, otherwise default. /// True if successful with assigned the value, otherwise false. - public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantity) + public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity? quantity) { switch (unit) {"); @@ -92,7 +94,7 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit /// Quantity string representation, such as ""1.5 kg"". Must be compatible with given quantity type. /// The resulting quantity if successful, otherwise default. /// The parsed quantity. - public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type quantityType, string quantityString, out IQuantity quantity) + public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, string quantityString, out IQuantity? quantity) { quantity = default(IQuantity); diff --git a/UnitsNet/CustomCode/Quantities/Length.extra.cs b/UnitsNet/CustomCode/Quantities/Length.extra.cs index 97f64c4805..c69d65fabf 100644 --- a/UnitsNet/CustomCode/Quantities/Length.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Length.extra.cs @@ -47,7 +47,7 @@ public static Length FromFeetInches(double feet, double inches) /// /// Optionally specify the culture format numbers and localize unit abbreviations. Defaults to thread's culture. /// Parsed length. - public static Length ParseFeetInches([NotNull] string str, IFormatProvider formatProvider = null) + public static Length ParseFeetInches([NotNull] string str, IFormatProvider? formatProvider = null) { if (str == null) throw new ArgumentNullException(nameof(str)); if (!TryParseFeetInches(str, out Length result, formatProvider)) @@ -69,7 +69,7 @@ public static Length ParseFeetInches([NotNull] string str, IFormatProvider forma /// /// Parsed length. /// Optionally specify the culture format numbers and localize unit abbreviations. Defaults to thread's culture. - public static bool TryParseFeetInches([CanBeNull] string str, out Length result, IFormatProvider formatProvider = null) + public static bool TryParseFeetInches(string? str, out Length result, IFormatProvider? formatProvider = null) { if (str == null) { @@ -213,7 +213,7 @@ public override string ToString() /// Optional culture to format number and localize unit abbreviations. /// If null, defaults to . /// - public string ToString([CanBeNull] IFormatProvider cultureInfo) + public string ToString(IFormatProvider? cultureInfo) { cultureInfo = cultureInfo ?? CultureInfo.CurrentUICulture; diff --git a/UnitsNet/CustomCode/Quantities/Mass.extra.cs b/UnitsNet/CustomCode/Quantities/Mass.extra.cs index 418adf58f8..b28c958182 100644 --- a/UnitsNet/CustomCode/Quantities/Mass.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Mass.extra.cs @@ -129,7 +129,7 @@ public override string ToString() /// Optional culture to format number and localize unit abbreviations. /// If null, defaults to . /// - public string ToString([CanBeNull] IFormatProvider cultureInfo) + public string ToString(IFormatProvider? cultureInfo) { cultureInfo = cultureInfo ?? CultureInfo.CurrentUICulture; diff --git a/UnitsNet/CustomCode/Quantity.cs b/UnitsNet/CustomCode/Quantity.cs index 74fe89d86d..7b3693d270 100644 --- a/UnitsNet/CustomCode/Quantity.cs +++ b/UnitsNet/CustomCode/Quantity.cs @@ -47,15 +47,15 @@ static Quantity() /// Unit value is not a know unit enum type. public static IQuantity From(QuantityValue value, Enum unit) { - if (TryFrom(value, unit, out IQuantity quantity)) - return quantity; + if (TryFrom(value, unit, out IQuantity? quantity)) + return quantity!; throw new ArgumentException( $"Unit value {unit} of type {unit.GetType()} is not a known unit enum type. Expected types like UnitsNet.Units.LengthUnit. Did you pass in a third-party enum type defined outside UnitsNet library?"); } /// - public static bool TryFrom(double value, Enum unit, out IQuantity quantity) + public static bool TryFrom(double value, Enum unit, out IQuantity? quantity) { // Implicit cast to QuantityValue would prevent TryFrom from being called, // so we need to explicitly check this here for double arguments. @@ -79,18 +79,19 @@ public static bool TryFrom(double value, Enum unit, out IQuantity quantity) /// Quantity string representation, such as "1.5 kg". Must be compatible with given quantity type. /// The parsed quantity. /// Type must be of type UnitsNet.IQuantity -or- Type is not a known quantity type. - public static IQuantity Parse([CanBeNull] IFormatProvider formatProvider, Type quantityType, string quantityString) + public static IQuantity Parse(IFormatProvider? formatProvider, Type quantityType, string quantityString) { if (!typeof(IQuantity).Wrap().IsAssignableFrom(quantityType)) throw new ArgumentException($"Type {quantityType} must be of type UnitsNet.IQuantity."); - if (TryParse(formatProvider, quantityType, quantityString, out IQuantity quantity)) return quantity; + if (TryParse(formatProvider, quantityType, quantityString, out IQuantity? quantity)) + return quantity!; throw new ArgumentException($"Quantity string could not be parsed to quantity {quantityType}."); } /// - public static bool TryParse(Type quantityType, string quantityString, out IQuantity quantity) => + public static bool TryParse(Type quantityType, string quantityString, out IQuantity? quantity) => TryParse(null, quantityType, quantityString, out quantity); /// diff --git a/UnitsNet/CustomCode/QuantityParser.cs b/UnitsNet/CustomCode/QuantityParser.cs index afe9db276f..a0054f5779 100644 --- a/UnitsNet/CustomCode/QuantityParser.cs +++ b/UnitsNet/CustomCode/QuantityParser.cs @@ -42,7 +42,7 @@ static QuantityParser() [SuppressMessage("ReSharper", "UseStringInterpolation")] internal TQuantity Parse([NotNull] string str, - [CanBeNull] IFormatProvider formatProvider, + IFormatProvider? formatProvider, [NotNull] QuantityFromDelegate fromDelegate) where TQuantity : IQuantity where TUnitType : Enum @@ -59,28 +59,28 @@ internal TQuantity Parse([NotNull] string str, var regex = CreateRegexForQuantity(formatProvider); - if (!ExtractValueAndUnit(regex, str, out var valueString, out var unitString)) + if (!TryExtractValueAndUnit(regex, str, out var valueString, out var unitString)) { var ex = new FormatException("Unable to parse quantity. Expected the form \"{value} {unit abbreviation}\", such as \"5.5 m\". The spacing is optional."); ex.Data["input"] = str; throw ex; } - return ParseWithRegex(valueString, unitString, fromDelegate, formatProvider); + return ParseWithRegex(valueString!, unitString!, fromDelegate, formatProvider); } [SuppressMessage("ReSharper", "UseStringInterpolation")] - internal bool TryParse([NotNull] string str, - [CanBeNull] IFormatProvider formatProvider, + internal bool TryParse(string? str, + IFormatProvider? formatProvider, [NotNull] QuantityFromDelegate fromDelegate, out TQuantity result) - where TQuantity : IQuantity - where TUnitType : Enum + where TQuantity : struct, IQuantity + where TUnitType : struct, Enum { result = default; if(string.IsNullOrWhiteSpace(str)) return false; - str = str.Trim(); + str = str!.Trim(); var numFormat = formatProvider != null ? (NumberFormatInfo) formatProvider.GetFormat(typeof(NumberFormatInfo)) @@ -91,7 +91,7 @@ internal bool TryParse([NotNull] string str, var regex = CreateRegexForQuantity(formatProvider); - if (!ExtractValueAndUnit(regex, str, out var valueString, out var unitString)) + if (!TryExtractValueAndUnit(regex, str, out var valueString, out var unitString)) return false; return TryParseWithRegex(valueString, unitString, fromDelegate, formatProvider, out result); @@ -102,11 +102,11 @@ internal bool TryParse([NotNull] string str, /// [SuppressMessage("ReSharper", "UseStringInterpolation")] internal bool TryParse([NotNull] string str, - [CanBeNull] IFormatProvider formatProvider, + IFormatProvider? formatProvider, [NotNull] QuantityFromDelegate fromDelegate, - out IQuantity result) - where TQuantity : IQuantity - where TUnitType : Enum + out IQuantity? result) + where TQuantity : struct, IQuantity + where TUnitType : struct, Enum { if (TryParse(str, formatProvider, fromDelegate, out TQuantity parsedQuantity)) { @@ -120,7 +120,7 @@ internal bool TryParse([NotNull] string str, internal string CreateRegexPatternForUnit( TUnitType unit, - IFormatProvider formatProvider, + IFormatProvider? formatProvider, bool matchEntireString = true) where TUnitType : Enum { @@ -147,7 +147,7 @@ private static string GetRegexPatternForUnitAbbreviations(IEnumerable ab private TQuantity ParseWithRegex(string valueString, string unitString, QuantityFromDelegate fromDelegate, - IFormatProvider formatProvider) + IFormatProvider? formatProvider) where TQuantity : IQuantity where TUnitType : Enum { @@ -160,13 +160,13 @@ private TQuantity ParseWithRegex(string valueString, /// Parse a string given a particular regular expression. /// /// Error parsing string. - private bool TryParseWithRegex(string valueString, - string unitString, + private bool TryParseWithRegex(string? valueString, + string? unitString, QuantityFromDelegate fromDelegate, - IFormatProvider formatProvider, + IFormatProvider? formatProvider, out TQuantity result) - where TQuantity : IQuantity - where TUnitType : Enum + where TQuantity : struct, IQuantity + where TUnitType : struct, Enum { result = default; @@ -180,7 +180,7 @@ private bool TryParseWithRegex(string valueString, return true; } - private static bool ExtractValueAndUnit(Regex regex, string str, out string valueString, out string unitString) + private static bool TryExtractValueAndUnit(Regex regex, string str, out string? valueString, out string? unitString) { var match = regex.Match(str); @@ -210,7 +210,7 @@ private static bool ExtractValueAndUnit(Regex regex, string str, out string valu return true; } - private string CreateRegexPatternForQuantity(IFormatProvider formatProvider) where TUnitType : Enum + private string CreateRegexPatternForQuantity(IFormatProvider? formatProvider) where TUnitType : Enum { var unitAbbreviations = _unitAbbreviationsCache.GetAllUnitAbbreviationsForQuantity(typeof(TUnitType), formatProvider); var pattern = GetRegexPatternForUnitAbbreviations(unitAbbreviations); @@ -219,7 +219,7 @@ private string CreateRegexPatternForQuantity(IFormatProvider formatPr return $"^{pattern}$"; } - private Regex CreateRegexForQuantity([CanBeNull] IFormatProvider formatProvider) where TUnitType : Enum + private Regex CreateRegexForQuantity(IFormatProvider? formatProvider) where TUnitType : Enum { var pattern = CreateRegexPatternForQuantity(formatProvider); return new Regex(pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase); diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs index d10b08b5fe..a0b52ff101 100644 --- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs +++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs @@ -192,7 +192,7 @@ private void PerformAbbreviationMapping(Type unitType, int unitValue, IFormatPro /// The type of unit enum. /// The default unit abbreviation string. [PublicAPI] - public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider formatProvider = null) where TUnitType : Enum + public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider? formatProvider = null) where TUnitType : Enum { var unitType = typeof(TUnitType); @@ -204,7 +204,7 @@ public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider throw new NotImplementedException($"No abbreviation is specified for {unitType.Name}.{unit}"); } - var abbreviations = lookup.GetAbbreviationsForUnit(unit); + var abbreviations = lookup!.GetAbbreviationsForUnit(unit); if(abbreviations.Count == 0) { if(formatProvider != FallbackCulture) @@ -226,7 +226,7 @@ public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider /// The format provider to use for lookup. Defaults to if null. /// The default unit abbreviation string. [PublicAPI] - public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvider formatProvider = null) + public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider = null) { if(!TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var lookup)) { @@ -236,7 +236,7 @@ public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvid throw new NotImplementedException($"No abbreviation is specified for {unitType.Name} with numeric value {unitValue}."); } - var abbreviations = lookup.GetAbbreviationsForUnit(unitValue); + var abbreviations = lookup!.GetAbbreviationsForUnit(unitValue); if(abbreviations.Count == 0) { if(formatProvider != FallbackCulture) @@ -256,7 +256,7 @@ public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvid /// The format provider to use for lookup. Defaults to if null. /// Unit abbreviations associated with unit. [PublicAPI] - public string[] GetUnitAbbreviations(TUnitType unit, IFormatProvider formatProvider = null) where TUnitType : Enum + public string[] GetUnitAbbreviations(TUnitType unit, IFormatProvider? formatProvider = null) where TUnitType : Enum { return GetUnitAbbreviations(typeof(TUnitType), Convert.ToInt32(unit), formatProvider); } @@ -269,14 +269,14 @@ public string[] GetUnitAbbreviations(TUnitType unit, IFormatProvider /// The format provider to use for lookup. Defaults to if null. /// Unit abbreviations associated with unit. [PublicAPI] - public string[] GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvider formatProvider = null) + public string[] GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvider? formatProvider = null) { formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; if(!TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var lookup)) return formatProvider != FallbackCulture ? GetUnitAbbreviations(unitType, unitValue, FallbackCulture) : new string[] { }; - var abbreviations = lookup.GetAbbreviationsForUnit(unitValue); + var abbreviations = lookup!.GetAbbreviationsForUnit(unitValue); if(abbreviations.Count == 0) return formatProvider != FallbackCulture ? GetUnitAbbreviations(unitType, unitValue, FallbackCulture) : new string[] { }; @@ -290,17 +290,17 @@ public string[] GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvid /// The format provider to use for lookup. Defaults to if null. /// Unit abbreviations associated with unit. [PublicAPI] - public string[] GetAllUnitAbbreviationsForQuantity(Type unitEnumType, IFormatProvider formatProvider = null) + public string[] GetAllUnitAbbreviationsForQuantity(Type unitEnumType, IFormatProvider? formatProvider = null) { formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; if(!TryGetUnitValueAbbreviationLookup(unitEnumType, formatProvider, out var lookup)) return formatProvider != FallbackCulture ? GetAllUnitAbbreviationsForQuantity(unitEnumType, FallbackCulture) : new string[] { }; - return lookup.GetAllUnitAbbreviationsForQuantity(); + return lookup!.GetAllUnitAbbreviationsForQuantity(); } - internal bool TryGetUnitValueAbbreviationLookup(Type unitType, IFormatProvider formatProvider, out UnitValueAbbreviationLookup unitToAbbreviations) + internal bool TryGetUnitValueAbbreviationLookup(Type unitType, IFormatProvider? formatProvider, out UnitValueAbbreviationLookup? unitToAbbreviations) { unitToAbbreviations = null; diff --git a/UnitsNet/CustomCode/UnitParser.cs b/UnitsNet/CustomCode/UnitParser.cs index ef254232a4..2becb1fd4d 100644 --- a/UnitsNet/CustomCode/UnitParser.cs +++ b/UnitsNet/CustomCode/UnitParser.cs @@ -48,7 +48,7 @@ static UnitParser() /// /// [PublicAPI] - public TUnitType Parse(string unitAbbreviation, [CanBeNull] IFormatProvider formatProvider = null) where TUnitType : Enum + public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null) where TUnitType : Enum { return (TUnitType)Parse(unitAbbreviation, typeof(TUnitType), formatProvider); } @@ -67,7 +67,7 @@ public TUnitType Parse(string unitAbbreviation, [CanBeNull] IFormatPr /// No units match the abbreviation. /// More than one unit matches the abbreviation. [PublicAPI] - public Enum Parse([NotNull] string unitAbbreviation, Type unitType, [CanBeNull] IFormatProvider formatProvider = null) + public Enum Parse([NotNull] string unitAbbreviation, Type unitType, IFormatProvider? formatProvider = null) { if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation)); unitAbbreviation = unitAbbreviation.Trim(); @@ -75,7 +75,7 @@ public Enum Parse([NotNull] string unitAbbreviation, Type unitType, [CanBeNull] if(!_unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations)) throw new UnitNotFoundException($"No abbreviations defined for unit type [{unitType}] for culture [{formatProvider}]."); - var unitIntValues = abbreviations.GetUnitsForAbbreviation(unitAbbreviation, ignoreCase: true); + var unitIntValues = abbreviations!.GetUnitsForAbbreviation(unitAbbreviation, ignoreCase: true); if (unitIntValues.Count == 0) { @@ -139,7 +139,7 @@ internal static string NormalizeUnitString(string unitAbbreviation) /// Type of unit enum. /// True if successful. [PublicAPI] - public bool TryParse(string unitAbbreviation, out TUnitType unit) where TUnitType : Enum + public bool TryParse(string unitAbbreviation, out TUnitType unit) where TUnitType : struct, Enum { return TryParse(unitAbbreviation, null, out unit); } @@ -153,14 +153,14 @@ public bool TryParse(string unitAbbreviation, out TUnitType unit) whe /// Type of unit enum. /// True if successful. [PublicAPI] - public bool TryParse(string unitAbbreviation, [CanBeNull] IFormatProvider formatProvider, out TUnitType unit) where TUnitType : Enum + public bool TryParse(string? unitAbbreviation, IFormatProvider? formatProvider, out TUnitType unit) where TUnitType : struct, Enum { unit = default; if(!TryParse(unitAbbreviation, typeof(TUnitType), formatProvider, out var unitObj)) return false; - unit = (TUnitType)unitObj; + unit = (TUnitType)unitObj!; return true; } @@ -172,7 +172,7 @@ public bool TryParse(string unitAbbreviation, [CanBeNull] IFormatProv /// The unit enum value as out result. /// True if successful. [PublicAPI] - public bool TryParse(string unitAbbreviation, Type unitType, out Enum unit) + public bool TryParse(string unitAbbreviation, Type unitType, out Enum? unit) { return TryParse(unitAbbreviation, unitType, null, out unit); } @@ -186,7 +186,7 @@ public bool TryParse(string unitAbbreviation, Type unitType, out Enum unit) /// The unit enum value as out result. /// True if successful. [PublicAPI] - public bool TryParse(string unitAbbreviation, Type unitType, [CanBeNull] IFormatProvider formatProvider, out Enum unit) + public bool TryParse(string? unitAbbreviation, Type unitType, IFormatProvider? formatProvider, out Enum? unit) { if (unitAbbreviation == null) { @@ -200,7 +200,7 @@ public bool TryParse(string unitAbbreviation, Type unitType, [CanBeNull] IFormat if(!_unitAbbreviationsCache.TryGetUnitValueAbbreviationLookup(unitType, formatProvider, out var abbreviations)) return false; - var unitIntValues = abbreviations.GetUnitsForAbbreviation(unitAbbreviation, ignoreCase: true); + var unitIntValues = abbreviations!.GetUnitsForAbbreviation(unitAbbreviation, ignoreCase: true); if (unitIntValues.Count == 0) { diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 39e69008d1..ed7f90771b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -92,7 +94,7 @@ public Acceleration(double value, AccelerationUnit unit) /// No unit was found for the given . public Acceleration(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -260,7 +262,7 @@ public static string GetAbbreviation(AccelerationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AccelerationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AccelerationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -452,7 +454,7 @@ public static Acceleration Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Acceleration Parse(string str, [CanBeNull] IFormatProvider provider) + public static Acceleration Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -468,7 +470,7 @@ public static Acceleration Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Acceleration result) + public static bool TryParse(string? str, out Acceleration result) { return TryParse(str, null, out result); } @@ -483,7 +485,7 @@ public static bool TryParse([CanBeNull] string str, out Acceleration result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Acceleration result) + public static bool TryParse(string? str, IFormatProvider? provider, out Acceleration result) { return QuantityParser.Default.TryParse( str, @@ -516,7 +518,7 @@ public static AccelerationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AccelerationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AccelerationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -537,7 +539,7 @@ public static bool TryParseUnit(string str, out AccelerationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AccelerationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AccelerationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -742,7 +744,7 @@ public double As(AccelerationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -785,7 +787,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Acceleration ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -889,7 +891,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -901,7 +903,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -916,7 +918,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -944,11 +946,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index 18abeba8bd..94b3ca9fd8 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -94,7 +96,7 @@ public AmountOfSubstance(double value, AmountOfSubstanceUnit unit) /// No unit was found for the given . public AmountOfSubstance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -272,7 +274,7 @@ public static string GetAbbreviation(AmountOfSubstanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AmountOfSubstanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AmountOfSubstanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -482,7 +484,7 @@ public static AmountOfSubstance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static AmountOfSubstance Parse(string str, [CanBeNull] IFormatProvider provider) + public static AmountOfSubstance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -498,7 +500,7 @@ public static AmountOfSubstance Parse(string str, [CanBeNull] IFormatProvider pr /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out AmountOfSubstance result) + public static bool TryParse(string? str, out AmountOfSubstance result) { return TryParse(str, null, out result); } @@ -513,7 +515,7 @@ public static bool TryParse([CanBeNull] string str, out AmountOfSubstance result /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AmountOfSubstance result) + public static bool TryParse(string? str, IFormatProvider? provider, out AmountOfSubstance result) { return QuantityParser.Default.TryParse( str, @@ -546,7 +548,7 @@ public static AmountOfSubstanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AmountOfSubstanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AmountOfSubstanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -567,7 +569,7 @@ public static bool TryParseUnit(string str, out AmountOfSubstanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AmountOfSubstanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AmountOfSubstanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -772,7 +774,7 @@ public double As(AmountOfSubstanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -815,7 +817,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public AmountOfSubstance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -923,7 +925,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -935,7 +937,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -950,7 +952,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -978,11 +980,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs index f0a38498f0..899d516ff6 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public AmplitudeRatio(double value, AmplitudeRatioUnit unit) /// No unit was found for the given . public AmplitudeRatio(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -206,7 +208,7 @@ public static string GetAbbreviation(AmplitudeRatioUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AmplitudeRatioUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AmplitudeRatioUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -317,7 +319,7 @@ public static AmplitudeRatio Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static AmplitudeRatio Parse(string str, [CanBeNull] IFormatProvider provider) + public static AmplitudeRatio Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -333,7 +335,7 @@ public static AmplitudeRatio Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out AmplitudeRatio result) + public static bool TryParse(string? str, out AmplitudeRatio result) { return TryParse(str, null, out result); } @@ -348,7 +350,7 @@ public static bool TryParse([CanBeNull] string str, out AmplitudeRatio result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AmplitudeRatio result) + public static bool TryParse(string? str, IFormatProvider? provider, out AmplitudeRatio result) { return QuantityParser.Default.TryParse( str, @@ -381,7 +383,7 @@ public static AmplitudeRatioUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AmplitudeRatioUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AmplitudeRatioUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -402,7 +404,7 @@ public static bool TryParseUnit(string str, out AmplitudeRatioUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AmplitudeRatioUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AmplitudeRatioUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -615,7 +617,7 @@ public double As(AmplitudeRatioUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -658,7 +660,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public AmplitudeRatio ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -744,7 +746,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -756,7 +758,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -771,7 +773,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -799,11 +801,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 64efe5550d..7299ad8473 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -93,7 +95,7 @@ public Angle(double value, AngleUnit unit) /// No unit was found for the given . public Angle(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -266,7 +268,7 @@ public static string GetAbbreviation(AngleUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AngleUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AngleUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -467,7 +469,7 @@ public static Angle Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Angle Parse(string str, [CanBeNull] IFormatProvider provider) + public static Angle Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -483,7 +485,7 @@ public static Angle Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Angle result) + public static bool TryParse(string? str, out Angle result) { return TryParse(str, null, out result); } @@ -498,7 +500,7 @@ public static bool TryParse([CanBeNull] string str, out Angle result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Angle result) + public static bool TryParse(string? str, IFormatProvider? provider, out Angle result) { return QuantityParser.Default.TryParse( str, @@ -531,7 +533,7 @@ public static AngleUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AngleUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AngleUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -552,7 +554,7 @@ public static bool TryParseUnit(string str, out AngleUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AngleUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AngleUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -757,7 +759,7 @@ public double As(AngleUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -800,7 +802,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Angle ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -906,7 +908,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -918,7 +920,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -933,7 +935,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -961,11 +963,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs index 9cee071934..895523d500 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public ApparentEnergy(double value, ApparentEnergyUnit unit) /// No unit was found for the given . public ApparentEnergy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(ApparentEnergyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ApparentEnergyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ApparentEnergyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static ApparentEnergy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ApparentEnergy Parse(string str, [CanBeNull] IFormatProvider provider) + public static ApparentEnergy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static ApparentEnergy Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ApparentEnergy result) + public static bool TryParse(string? str, out ApparentEnergy result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out ApparentEnergy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ApparentEnergy result) + public static bool TryParse(string? str, IFormatProvider? provider, out ApparentEnergy result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static ApparentEnergyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ApparentEnergyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ApparentEnergyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out ApparentEnergyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ApparentEnergyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ApparentEnergyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(ApparentEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ApparentEnergy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs index 951f5b4370..269c94cd4d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public ApparentPower(double value, ApparentPowerUnit unit) /// No unit was found for the given . public ApparentPower(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -206,7 +208,7 @@ public static string GetAbbreviation(ApparentPowerUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ApparentPowerUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ApparentPowerUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -317,7 +319,7 @@ public static ApparentPower Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ApparentPower Parse(string str, [CanBeNull] IFormatProvider provider) + public static ApparentPower Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -333,7 +335,7 @@ public static ApparentPower Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ApparentPower result) + public static bool TryParse(string? str, out ApparentPower result) { return TryParse(str, null, out result); } @@ -348,7 +350,7 @@ public static bool TryParse([CanBeNull] string str, out ApparentPower result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ApparentPower result) + public static bool TryParse(string? str, IFormatProvider? provider, out ApparentPower result) { return QuantityParser.Default.TryParse( str, @@ -381,7 +383,7 @@ public static ApparentPowerUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ApparentPowerUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ApparentPowerUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -402,7 +404,7 @@ public static bool TryParseUnit(string str, out ApparentPowerUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ApparentPowerUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ApparentPowerUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -607,7 +609,7 @@ public double As(ApparentPowerUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -650,7 +652,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ApparentPower ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -736,7 +738,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -748,7 +750,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -763,7 +765,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -791,11 +793,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index 07241d5540..d5f3d94ed7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -93,7 +95,7 @@ public Area(double value, AreaUnit unit) /// No unit was found for the given . public Area(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -266,7 +268,7 @@ public static string GetAbbreviation(AreaUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AreaUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AreaUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -467,7 +469,7 @@ public static Area Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Area Parse(string str, [CanBeNull] IFormatProvider provider) + public static Area Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -483,7 +485,7 @@ public static Area Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Area result) + public static bool TryParse(string? str, out Area result) { return TryParse(str, null, out result); } @@ -498,7 +500,7 @@ public static bool TryParse([CanBeNull] string str, out Area result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Area result) + public static bool TryParse(string? str, IFormatProvider? provider, out Area result) { return QuantityParser.Default.TryParse( str, @@ -531,7 +533,7 @@ public static AreaUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AreaUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AreaUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -552,7 +554,7 @@ public static bool TryParseUnit(string str, out AreaUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AreaUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -757,7 +759,7 @@ public double As(AreaUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -800,7 +802,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Area ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -906,7 +908,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -918,7 +920,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -933,7 +935,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -961,11 +963,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs index b4e3655c0d..e5b4215ceb 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -80,7 +82,7 @@ public AreaDensity(double value, AreaDensityUnit unit) /// No unit was found for the given . public AreaDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -188,7 +190,7 @@ public static string GetAbbreviation(AreaDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AreaDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AreaDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -272,7 +274,7 @@ public static AreaDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static AreaDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static AreaDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -288,7 +290,7 @@ public static AreaDensity Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out AreaDensity result) + public static bool TryParse(string? str, out AreaDensity result) { return TryParse(str, null, out result); } @@ -303,7 +305,7 @@ public static bool TryParse([CanBeNull] string str, out AreaDensity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AreaDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out AreaDensity result) { return QuantityParser.Default.TryParse( str, @@ -336,7 +338,7 @@ public static AreaDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AreaDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AreaDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -357,7 +359,7 @@ public static bool TryParseUnit(string str, out AreaDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AreaDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -562,7 +564,7 @@ public double As(AreaDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -605,7 +607,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public AreaDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -685,7 +687,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -697,7 +699,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -712,7 +714,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -740,11 +742,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index 1d4d806463..8d9872efab 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public AreaMomentOfInertia(double value, AreaMomentOfInertiaUnit unit) /// No unit was found for the given . public AreaMomentOfInertia(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -218,7 +220,7 @@ public static string GetAbbreviation(AreaMomentOfInertiaUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(AreaMomentOfInertiaUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(AreaMomentOfInertiaUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -347,7 +349,7 @@ public static AreaMomentOfInertia Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static AreaMomentOfInertia Parse(string str, [CanBeNull] IFormatProvider provider) + public static AreaMomentOfInertia Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -363,7 +365,7 @@ public static AreaMomentOfInertia Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out AreaMomentOfInertia result) + public static bool TryParse(string? str, out AreaMomentOfInertia result) { return TryParse(str, null, out result); } @@ -378,7 +380,7 @@ public static bool TryParse([CanBeNull] string str, out AreaMomentOfInertia resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AreaMomentOfInertia result) + public static bool TryParse(string? str, IFormatProvider? provider, out AreaMomentOfInertia result) { return QuantityParser.Default.TryParse( str, @@ -411,7 +413,7 @@ public static AreaMomentOfInertiaUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static AreaMomentOfInertiaUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static AreaMomentOfInertiaUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -432,7 +434,7 @@ public static bool TryParseUnit(string str, out AreaMomentOfInertiaUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out AreaMomentOfInertiaUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaMomentOfInertiaUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -637,7 +639,7 @@ public double As(AreaMomentOfInertiaUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -680,7 +682,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public AreaMomentOfInertia ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -770,7 +772,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -782,7 +784,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -797,7 +799,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -825,11 +827,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs index c3539d1999..c7e6ad0c0e 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -108,7 +110,7 @@ public BitRate(decimal value, BitRateUnit unit) /// No unit was found for the given . public BitRate(decimal value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -343,7 +345,7 @@ public static string GetAbbreviation(BitRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(BitRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(BitRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -652,7 +654,7 @@ public static BitRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static BitRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static BitRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -668,7 +670,7 @@ public static BitRate Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out BitRate result) + public static bool TryParse(string? str, out BitRate result) { return TryParse(str, null, out result); } @@ -683,7 +685,7 @@ public static bool TryParse([CanBeNull] string str, out BitRate result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out BitRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out BitRate result) { return QuantityParser.Default.TryParse( str, @@ -716,7 +718,7 @@ public static BitRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static BitRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static BitRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -737,7 +739,7 @@ public static bool TryParseUnit(string str, out BitRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out BitRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out BitRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -942,7 +944,7 @@ public double As(BitRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -985,7 +987,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public BitRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1115,7 +1117,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1127,7 +1129,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1142,7 +1144,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1170,11 +1172,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs index 13c1919e53..ec856aa869 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public BrakeSpecificFuelConsumption(double value, BrakeSpecificFuelConsumptionUn /// No unit was found for the given . public BrakeSpecificFuelConsumption(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static BrakeSpecificFuelConsumption Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static BrakeSpecificFuelConsumption Parse(string str, [CanBeNull] IFormatProvider provider) + public static BrakeSpecificFuelConsumption Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static BrakeSpecificFuelConsumption Parse(string str, [CanBeNull] IFormat /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out BrakeSpecificFuelConsumption result) + public static bool TryParse(string? str, out BrakeSpecificFuelConsumption result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out BrakeSpecificFuelConsump /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out BrakeSpecificFuelConsumption result) + public static bool TryParse(string? str, IFormatProvider? provider, out BrakeSpecificFuelConsumption result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out BrakeSpecificFuelConsumptionUnit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out BrakeSpecificFuelConsumptionUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out BrakeSpecificFuelConsumptionUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(BrakeSpecificFuelConsumptionUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public BrakeSpecificFuelConsumption ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs index d3f61dfd10..cfdce7831f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public Capacitance(double value, CapacitanceUnit unit) /// No unit was found for the given . public Capacitance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -227,7 +229,7 @@ public static string GetAbbreviation(CapacitanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(CapacitanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(CapacitanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -365,7 +367,7 @@ public static Capacitance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Capacitance Parse(string str, [CanBeNull] IFormatProvider provider) + public static Capacitance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -381,7 +383,7 @@ public static Capacitance Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Capacitance result) + public static bool TryParse(string? str, out Capacitance result) { return TryParse(str, null, out result); } @@ -396,7 +398,7 @@ public static bool TryParse([CanBeNull] string str, out Capacitance result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Capacitance result) + public static bool TryParse(string? str, IFormatProvider? provider, out Capacitance result) { return QuantityParser.Default.TryParse( str, @@ -429,7 +431,7 @@ public static CapacitanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static CapacitanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static CapacitanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -450,7 +452,7 @@ public static bool TryParseUnit(string str, out CapacitanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out CapacitanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out CapacitanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -655,7 +657,7 @@ public double As(CapacitanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -698,7 +700,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Capacitance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -790,7 +792,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -802,7 +804,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -817,7 +819,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -845,11 +847,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index 46a7fac2af..284ff62318 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public CoefficientOfThermalExpansion(double value, CoefficientOfThermalExpansion /// No unit was found for the given . public CoefficientOfThermalExpansion(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(CoefficientOfThermalExpansionUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(CoefficientOfThermalExpansionUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(CoefficientOfThermalExpansionUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static CoefficientOfThermalExpansion Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static CoefficientOfThermalExpansion Parse(string str, [CanBeNull] IFormatProvider provider) + public static CoefficientOfThermalExpansion Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static CoefficientOfThermalExpansion Parse(string str, [CanBeNull] IForma /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out CoefficientOfThermalExpansion result) + public static bool TryParse(string? str, out CoefficientOfThermalExpansion result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out CoefficientOfThermalExpa /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out CoefficientOfThermalExpansion result) + public static bool TryParse(string? str, IFormatProvider? provider, out CoefficientOfThermalExpansion result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static CoefficientOfThermalExpansionUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static CoefficientOfThermalExpansionUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static CoefficientOfThermalExpansionUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out CoefficientOfThermalExpansionUni /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out CoefficientOfThermalExpansionUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out CoefficientOfThermalExpansionUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(CoefficientOfThermalExpansionUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public CoefficientOfThermalExpansion ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index c22b5734eb..da5c1bbd5b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -122,7 +124,7 @@ public Density(double value, DensityUnit unit) /// No unit was found for the given . public Density(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -425,7 +427,7 @@ public static string GetAbbreviation(DensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(DensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(DensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -860,7 +862,7 @@ public static Density Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Density Parse(string str, [CanBeNull] IFormatProvider provider) + public static Density Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -876,7 +878,7 @@ public static Density Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Density result) + public static bool TryParse(string? str, out Density result) { return TryParse(str, null, out result); } @@ -891,7 +893,7 @@ public static bool TryParse([CanBeNull] string str, out Density result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Density result) + public static bool TryParse(string? str, IFormatProvider? provider, out Density result) { return QuantityParser.Default.TryParse( str, @@ -924,7 +926,7 @@ public static DensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static DensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static DensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -945,7 +947,7 @@ public static bool TryParseUnit(string str, out DensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out DensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out DensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1150,7 +1152,7 @@ public double As(DensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1193,7 +1195,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Density ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1351,7 +1353,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1363,7 +1365,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1378,7 +1380,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1406,11 +1408,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index 334f988875..8dfbec5b24 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public Duration(double value, DurationUnit unit) /// No unit was found for the given . public Duration(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -242,7 +244,7 @@ public static string GetAbbreviation(DurationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(DurationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(DurationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -407,7 +409,7 @@ public static Duration Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Duration Parse(string str, [CanBeNull] IFormatProvider provider) + public static Duration Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -423,7 +425,7 @@ public static Duration Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Duration result) + public static bool TryParse(string? str, out Duration result) { return TryParse(str, null, out result); } @@ -438,7 +440,7 @@ public static bool TryParse([CanBeNull] string str, out Duration result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Duration result) + public static bool TryParse(string? str, IFormatProvider? provider, out Duration result) { return QuantityParser.Default.TryParse( str, @@ -471,7 +473,7 @@ public static DurationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static DurationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static DurationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -492,7 +494,7 @@ public static bool TryParseUnit(string str, out DurationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out DurationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out DurationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -697,7 +699,7 @@ public double As(DurationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -740,7 +742,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Duration ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -838,7 +840,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -850,7 +852,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -865,7 +867,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -893,11 +895,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index 4c734b5014..3ced8d43ee 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -91,7 +93,7 @@ public DynamicViscosity(double value, DynamicViscosityUnit unit) /// No unit was found for the given . public DynamicViscosity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -239,7 +241,7 @@ public static string GetAbbreviation(DynamicViscosityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(DynamicViscosityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(DynamicViscosityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -395,7 +397,7 @@ public static DynamicViscosity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static DynamicViscosity Parse(string str, [CanBeNull] IFormatProvider provider) + public static DynamicViscosity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -411,7 +413,7 @@ public static DynamicViscosity Parse(string str, [CanBeNull] IFormatProvider pro /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out DynamicViscosity result) + public static bool TryParse(string? str, out DynamicViscosity result) { return TryParse(str, null, out result); } @@ -426,7 +428,7 @@ public static bool TryParse([CanBeNull] string str, out DynamicViscosity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out DynamicViscosity result) + public static bool TryParse(string? str, IFormatProvider? provider, out DynamicViscosity result) { return QuantityParser.Default.TryParse( str, @@ -459,7 +461,7 @@ public static DynamicViscosityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static DynamicViscosityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static DynamicViscosityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -480,7 +482,7 @@ public static bool TryParseUnit(string str, out DynamicViscosityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out DynamicViscosityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out DynamicViscosityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -685,7 +687,7 @@ public double As(DynamicViscosityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -728,7 +730,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public DynamicViscosity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -824,7 +826,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -836,7 +838,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -851,7 +853,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -879,11 +881,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 7fea23f989..4d32562157 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public ElectricAdmittance(double value, ElectricAdmittanceUnit unit) /// No unit was found for the given . public ElectricAdmittance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -206,7 +208,7 @@ public static string GetAbbreviation(ElectricAdmittanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricAdmittanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricAdmittanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -317,7 +319,7 @@ public static ElectricAdmittance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricAdmittance Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricAdmittance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -333,7 +335,7 @@ public static ElectricAdmittance Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricAdmittance result) + public static bool TryParse(string? str, out ElectricAdmittance result) { return TryParse(str, null, out result); } @@ -348,7 +350,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricAdmittance resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricAdmittance result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricAdmittance result) { return QuantityParser.Default.TryParse( str, @@ -381,7 +383,7 @@ public static ElectricAdmittanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricAdmittanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricAdmittanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -402,7 +404,7 @@ public static bool TryParseUnit(string str, out ElectricAdmittanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricAdmittanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricAdmittanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -607,7 +609,7 @@ public double As(ElectricAdmittanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -650,7 +652,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricAdmittance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -736,7 +738,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -748,7 +750,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -763,7 +765,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -791,11 +793,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index 9d06a5e7f1..d441ab525e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -87,7 +89,7 @@ public ElectricCharge(double value, ElectricChargeUnit unit) /// No unit was found for the given . public ElectricCharge(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -215,7 +217,7 @@ public static string GetAbbreviation(ElectricChargeUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricChargeUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricChargeUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -335,7 +337,7 @@ public static ElectricCharge Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricCharge Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCharge Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -351,7 +353,7 @@ public static ElectricCharge Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricCharge result) + public static bool TryParse(string? str, out ElectricCharge result) { return TryParse(str, null, out result); } @@ -366,7 +368,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricCharge result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCharge result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricCharge result) { return QuantityParser.Default.TryParse( str, @@ -399,7 +401,7 @@ public static ElectricChargeUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricChargeUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricChargeUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -420,7 +422,7 @@ public static bool TryParseUnit(string str, out ElectricChargeUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricChargeUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricChargeUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -625,7 +627,7 @@ public double As(ElectricChargeUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -668,7 +670,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricCharge ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -756,7 +758,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -768,7 +770,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -783,7 +785,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -811,11 +813,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs index 84babf87b7..7eee888c9e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public ElectricChargeDensity(double value, ElectricChargeDensityUnit unit) /// No unit was found for the given . public ElectricChargeDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(ElectricChargeDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricChargeDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricChargeDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static ElectricChargeDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricChargeDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricChargeDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static ElectricChargeDensity Parse(string str, [CanBeNull] IFormatProvide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricChargeDensity result) + public static bool TryParse(string? str, out ElectricChargeDensity result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricChargeDensity re /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricChargeDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricChargeDensity result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static ElectricChargeDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricChargeDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricChargeDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out ElectricChargeDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricChargeDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricChargeDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(ElectricChargeDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricChargeDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index 0dffcbc32b..9057adb96e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public ElectricConductance(double value, ElectricConductanceUnit unit) /// No unit was found for the given . public ElectricConductance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -203,7 +205,7 @@ public static string GetAbbreviation(ElectricConductanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricConductanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricConductanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -305,7 +307,7 @@ public static ElectricConductance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricConductance Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricConductance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -321,7 +323,7 @@ public static ElectricConductance Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricConductance result) + public static bool TryParse(string? str, out ElectricConductance result) { return TryParse(str, null, out result); } @@ -336,7 +338,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricConductance resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricConductance result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricConductance result) { return QuantityParser.Default.TryParse( str, @@ -369,7 +371,7 @@ public static ElectricConductanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricConductanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricConductanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -390,7 +392,7 @@ public static bool TryParseUnit(string str, out ElectricConductanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricConductanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricConductanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -595,7 +597,7 @@ public double As(ElectricConductanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -638,7 +640,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricConductance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -722,7 +724,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -734,7 +736,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -749,7 +751,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -777,11 +779,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs index c3ed929ce6..d55f01f9c8 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public ElectricConductivity(double value, ElectricConductivityUnit unit) /// No unit was found for the given . public ElectricConductivity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -203,7 +205,7 @@ public static string GetAbbreviation(ElectricConductivityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricConductivityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricConductivityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -305,7 +307,7 @@ public static ElectricConductivity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricConductivity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricConductivity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -321,7 +323,7 @@ public static ElectricConductivity Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricConductivity result) + public static bool TryParse(string? str, out ElectricConductivity result) { return TryParse(str, null, out result); } @@ -336,7 +338,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricConductivity res /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricConductivity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricConductivity result) { return QuantityParser.Default.TryParse( str, @@ -369,7 +371,7 @@ public static ElectricConductivityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricConductivityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricConductivityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -390,7 +392,7 @@ public static bool TryParseUnit(string str, out ElectricConductivityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricConductivityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricConductivityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -595,7 +597,7 @@ public double As(ElectricConductivityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -638,7 +640,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricConductivity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -722,7 +724,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -734,7 +736,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -749,7 +751,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -777,11 +779,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 13726a1360..23877d8b2b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -87,7 +89,7 @@ public ElectricCurrent(double value, ElectricCurrentUnit unit) /// No unit was found for the given . public ElectricCurrent(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -230,7 +232,7 @@ public static string GetAbbreviation(ElectricCurrentUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricCurrentUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricCurrentUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -377,7 +379,7 @@ public static ElectricCurrent Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricCurrent Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrent Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -393,7 +395,7 @@ public static ElectricCurrent Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricCurrent result) + public static bool TryParse(string? str, out ElectricCurrent result) { return TryParse(str, null, out result); } @@ -408,7 +410,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricCurrent result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrent result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricCurrent result) { return QuantityParser.Default.TryParse( str, @@ -441,7 +443,7 @@ public static ElectricCurrentUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricCurrentUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrentUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -462,7 +464,7 @@ public static bool TryParseUnit(string str, out ElectricCurrentUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricCurrentUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricCurrentUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -667,7 +669,7 @@ public double As(ElectricCurrentUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -710,7 +712,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricCurrent ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -804,7 +806,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -816,7 +818,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -831,7 +833,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -859,11 +861,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs index 40b235fe08..25fbd5bc4c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public ElectricCurrentDensity(double value, ElectricCurrentDensityUnit unit) /// No unit was found for the given . public ElectricCurrentDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -203,7 +205,7 @@ public static string GetAbbreviation(ElectricCurrentDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricCurrentDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricCurrentDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -305,7 +307,7 @@ public static ElectricCurrentDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricCurrentDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrentDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -321,7 +323,7 @@ public static ElectricCurrentDensity Parse(string str, [CanBeNull] IFormatProvid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricCurrentDensity result) + public static bool TryParse(string? str, out ElectricCurrentDensity result) { return TryParse(str, null, out result); } @@ -336,7 +338,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricCurrentDensity r /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrentDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricCurrentDensity result) { return QuantityParser.Default.TryParse( str, @@ -369,7 +371,7 @@ public static ElectricCurrentDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricCurrentDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrentDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -390,7 +392,7 @@ public static bool TryParseUnit(string str, out ElectricCurrentDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricCurrentDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricCurrentDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -595,7 +597,7 @@ public double As(ElectricCurrentDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -638,7 +640,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricCurrentDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -722,7 +724,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -734,7 +736,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -749,7 +751,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -777,11 +779,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index c5366cb423..e76eaeaa5c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -80,7 +82,7 @@ public ElectricCurrentGradient(double value, ElectricCurrentGradientUnit unit) /// No unit was found for the given . public ElectricCurrentGradient(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -188,7 +190,7 @@ public static string GetAbbreviation(ElectricCurrentGradientUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricCurrentGradientUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricCurrentGradientUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -272,7 +274,7 @@ public static ElectricCurrentGradient Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricCurrentGradient Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrentGradient Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -288,7 +290,7 @@ public static ElectricCurrentGradient Parse(string str, [CanBeNull] IFormatProvi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricCurrentGradient result) + public static bool TryParse(string? str, out ElectricCurrentGradient result) { return TryParse(str, null, out result); } @@ -303,7 +305,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricCurrentGradient /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrentGradient result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricCurrentGradient result) { return QuantityParser.Default.TryParse( str, @@ -336,7 +338,7 @@ public static ElectricCurrentGradientUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricCurrentGradientUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricCurrentGradientUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -357,7 +359,7 @@ public static bool TryParseUnit(string str, out ElectricCurrentGradientUnit unit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricCurrentGradientUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricCurrentGradientUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -562,7 +564,7 @@ public double As(ElectricCurrentGradientUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -605,7 +607,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricCurrentGradient ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -685,7 +687,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -697,7 +699,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -712,7 +714,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -740,11 +742,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs index 0a388a3fbc..9a611d2ece 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public ElectricField(double value, ElectricFieldUnit unit) /// No unit was found for the given . public ElectricField(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(ElectricFieldUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricFieldUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricFieldUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static ElectricField Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricField Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricField Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static ElectricField Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricField result) + public static bool TryParse(string? str, out ElectricField result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricField result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricField result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricField result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static ElectricFieldUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricFieldUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricFieldUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out ElectricFieldUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricFieldUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricFieldUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(ElectricFieldUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricField ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs index 47282ca714..a35692e319 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public ElectricInductance(double value, ElectricInductanceUnit unit) /// No unit was found for the given . public ElectricInductance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -209,7 +211,7 @@ public static string GetAbbreviation(ElectricInductanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricInductanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricInductanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -320,7 +322,7 @@ public static ElectricInductance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricInductance Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricInductance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -336,7 +338,7 @@ public static ElectricInductance Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricInductance result) + public static bool TryParse(string? str, out ElectricInductance result) { return TryParse(str, null, out result); } @@ -351,7 +353,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricInductance resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricInductance result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricInductance result) { return QuantityParser.Default.TryParse( str, @@ -384,7 +386,7 @@ public static ElectricInductanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricInductanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricInductanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -405,7 +407,7 @@ public static bool TryParseUnit(string str, out ElectricInductanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricInductanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricInductanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -610,7 +612,7 @@ public double As(ElectricInductanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -653,7 +655,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricInductance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -739,7 +741,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -751,7 +753,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -766,7 +768,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -794,11 +796,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index e1a6cccc54..7bbac7191b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ElectricPotential(double value, ElectricPotentialUnit unit) /// No unit was found for the given . public ElectricPotential(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(ElectricPotentialUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricPotentialUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static ElectricPotential Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotential Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotential Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static ElectricPotential Parse(string str, [CanBeNull] IFormatProvider pr /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricPotential result) + public static bool TryParse(string? str, out ElectricPotential result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricPotential result /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotential result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotential result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static ElectricPotentialUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricPotentialUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out ElectricPotentialUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricPotentialUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(ElectricPotentialUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricPotential ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs index 37892c41ef..652d9c8d04 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ElectricPotentialAc(double value, ElectricPotentialAcUnit unit) /// No unit was found for the given . public ElectricPotentialAc(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(ElectricPotentialAcUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialAcUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricPotentialAcUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static ElectricPotentialAc Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotentialAc Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialAc Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static ElectricPotentialAc Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricPotentialAc result) + public static bool TryParse(string? str, out ElectricPotentialAc result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricPotentialAc resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialAc result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotentialAc result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static ElectricPotentialAcUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricPotentialAcUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialAcUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out ElectricPotentialAcUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricPotentialAcUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialAcUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(ElectricPotentialAcUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricPotentialAc ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs index 9dbe58e823..dc66e7a1aa 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -99,7 +101,7 @@ public ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit /// No unit was found for the given . public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -302,7 +304,7 @@ public static string GetAbbreviation(ElectricPotentialChangeRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricPotentialChangeRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -557,7 +559,7 @@ public static ElectricPotentialChangeRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotentialChangeRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialChangeRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -573,7 +575,7 @@ public static ElectricPotentialChangeRate Parse(string str, [CanBeNull] IFormatP /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricPotentialChangeRate result) + public static bool TryParse(string? str, out ElectricPotentialChangeRate result) { return TryParse(str, null, out result); } @@ -588,7 +590,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricPotentialChangeR /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialChangeRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotentialChangeRate result) { return QuantityParser.Default.TryParse( str, @@ -621,7 +623,7 @@ public static ElectricPotentialChangeRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricPotentialChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialChangeRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -642,7 +644,7 @@ public static bool TryParseUnit(string str, out ElectricPotentialChangeRateUnit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricPotentialChangeRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialChangeRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -847,7 +849,7 @@ public double As(ElectricPotentialChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -890,7 +892,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricPotentialChangeRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1008,7 +1010,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1020,7 +1022,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1035,7 +1037,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1063,11 +1065,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs index dedbe936b8..e22e2c3ad7 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ElectricPotentialDc(double value, ElectricPotentialDcUnit unit) /// No unit was found for the given . public ElectricPotentialDc(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(ElectricPotentialDcUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialDcUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricPotentialDcUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static ElectricPotentialDc Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotentialDc Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialDc Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static ElectricPotentialDc Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricPotentialDc result) + public static bool TryParse(string? str, out ElectricPotentialDc result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricPotentialDc resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialDc result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotentialDc result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static ElectricPotentialDcUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricPotentialDcUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricPotentialDcUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out ElectricPotentialDcUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricPotentialDcUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialDcUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(ElectricPotentialDcUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricPotentialDc ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index 8c96c4745e..83f7f5476d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ElectricResistance(double value, ElectricResistanceUnit unit) /// No unit was found for the given . public ElectricResistance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(ElectricResistanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricResistanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricResistanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static ElectricResistance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricResistance Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricResistance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static ElectricResistance Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricResistance result) + public static bool TryParse(string? str, out ElectricResistance result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricResistance resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricResistance result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricResistance result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static ElectricResistanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricResistanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricResistanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out ElectricResistanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricResistanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricResistanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(ElectricResistanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricResistance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs index b6a6f1427f..41d0b2791d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -96,7 +98,7 @@ public ElectricResistivity(double value, ElectricResistivityUnit unit) /// No unit was found for the given . public ElectricResistivity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -269,7 +271,7 @@ public static string GetAbbreviation(ElectricResistivityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricResistivityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricResistivityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -470,7 +472,7 @@ public static ElectricResistivity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricResistivity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricResistivity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -486,7 +488,7 @@ public static ElectricResistivity Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricResistivity result) + public static bool TryParse(string? str, out ElectricResistivity result) { return TryParse(str, null, out result); } @@ -501,7 +503,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricResistivity resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricResistivity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricResistivity result) { return QuantityParser.Default.TryParse( str, @@ -534,7 +536,7 @@ public static ElectricResistivityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricResistivityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricResistivityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -555,7 +557,7 @@ public static bool TryParseUnit(string str, out ElectricResistivityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricResistivityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricResistivityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -760,7 +762,7 @@ public double As(ElectricResistivityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -803,7 +805,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricResistivity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -909,7 +911,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -921,7 +923,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -936,7 +938,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -964,11 +966,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs index d8332d038a..98ce454741 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public ElectricSurfaceChargeDensity(double value, ElectricSurfaceChargeDensityUn /// No unit was found for the given . public ElectricSurfaceChargeDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -203,7 +205,7 @@ public static string GetAbbreviation(ElectricSurfaceChargeDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricSurfaceChargeDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ElectricSurfaceChargeDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -305,7 +307,7 @@ public static ElectricSurfaceChargeDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricSurfaceChargeDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ElectricSurfaceChargeDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -321,7 +323,7 @@ public static ElectricSurfaceChargeDensity Parse(string str, [CanBeNull] IFormat /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ElectricSurfaceChargeDensity result) + public static bool TryParse(string? str, out ElectricSurfaceChargeDensity result) { return TryParse(str, null, out result); } @@ -336,7 +338,7 @@ public static bool TryParse([CanBeNull] string str, out ElectricSurfaceChargeDen /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricSurfaceChargeDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ElectricSurfaceChargeDensity result) { return QuantityParser.Default.TryParse( str, @@ -369,7 +371,7 @@ public static ElectricSurfaceChargeDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ElectricSurfaceChargeDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ElectricSurfaceChargeDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -390,7 +392,7 @@ public static bool TryParseUnit(string str, out ElectricSurfaceChargeDensityUnit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ElectricSurfaceChargeDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricSurfaceChargeDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -595,7 +597,7 @@ public double As(ElectricSurfaceChargeDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -638,7 +640,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ElectricSurfaceChargeDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -722,7 +724,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -734,7 +736,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -749,7 +751,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -777,11 +779,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index 9977662665..eb59bdee80 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -114,7 +116,7 @@ public Energy(double value, EnergyUnit unit) /// No unit was found for the given . public Energy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -392,7 +394,7 @@ public static string GetAbbreviation(EnergyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(EnergyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(EnergyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -782,7 +784,7 @@ public static Energy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Energy Parse(string str, [CanBeNull] IFormatProvider provider) + public static Energy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -798,7 +800,7 @@ public static Energy Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Energy result) + public static bool TryParse(string? str, out Energy result) { return TryParse(str, null, out result); } @@ -813,7 +815,7 @@ public static bool TryParse([CanBeNull] string str, out Energy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Energy result) + public static bool TryParse(string? str, IFormatProvider? provider, out Energy result) { return QuantityParser.Default.TryParse( str, @@ -846,7 +848,7 @@ public static EnergyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static EnergyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static EnergyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -867,7 +869,7 @@ public static bool TryParseUnit(string str, out EnergyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out EnergyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out EnergyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1072,7 +1074,7 @@ public double As(EnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1115,7 +1117,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Energy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1263,7 +1265,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1275,7 +1277,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1290,7 +1292,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1318,11 +1320,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index c787d63860..4d22327766 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public Entropy(double value, EntropyUnit unit) /// No unit was found for the given . public Entropy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -224,7 +226,7 @@ public static string GetAbbreviation(EntropyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(EntropyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(EntropyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -362,7 +364,7 @@ public static Entropy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Entropy Parse(string str, [CanBeNull] IFormatProvider provider) + public static Entropy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -378,7 +380,7 @@ public static Entropy Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Entropy result) + public static bool TryParse(string? str, out Entropy result) { return TryParse(str, null, out result); } @@ -393,7 +395,7 @@ public static bool TryParse([CanBeNull] string str, out Entropy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Entropy result) + public static bool TryParse(string? str, IFormatProvider? provider, out Entropy result) { return QuantityParser.Default.TryParse( str, @@ -426,7 +428,7 @@ public static EntropyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static EntropyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static EntropyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -447,7 +449,7 @@ public static bool TryParseUnit(string str, out EntropyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out EntropyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out EntropyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -652,7 +654,7 @@ public double As(EntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -695,7 +697,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Entropy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -787,7 +789,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -799,7 +801,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -814,7 +816,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -842,11 +844,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index 98be579b24..4ae5d7bb02 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -93,7 +95,7 @@ public Force(double value, ForceUnit unit) /// No unit was found for the given . public Force(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -266,7 +268,7 @@ public static string GetAbbreviation(ForceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ForceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ForceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -467,7 +469,7 @@ public static Force Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Force Parse(string str, [CanBeNull] IFormatProvider provider) + public static Force Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -483,7 +485,7 @@ public static Force Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Force result) + public static bool TryParse(string? str, out Force result) { return TryParse(str, null, out result); } @@ -498,7 +500,7 @@ public static bool TryParse([CanBeNull] string str, out Force result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Force result) + public static bool TryParse(string? str, IFormatProvider? provider, out Force result) { return QuantityParser.Default.TryParse( str, @@ -531,7 +533,7 @@ public static ForceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ForceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ForceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -552,7 +554,7 @@ public static bool TryParseUnit(string str, out ForceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ForceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ForceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -757,7 +759,7 @@ public double As(ForceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -800,7 +802,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Force ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -906,7 +908,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -918,7 +920,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -933,7 +935,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -961,11 +963,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index 1d5bf52173..6b0737e640 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -90,7 +92,7 @@ public ForceChangeRate(double value, ForceChangeRateUnit unit) /// No unit was found for the given . public ForceChangeRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -248,7 +250,7 @@ public static string GetAbbreviation(ForceChangeRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ForceChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ForceChangeRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -422,7 +424,7 @@ public static ForceChangeRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ForceChangeRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static ForceChangeRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -438,7 +440,7 @@ public static ForceChangeRate Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ForceChangeRate result) + public static bool TryParse(string? str, out ForceChangeRate result) { return TryParse(str, null, out result); } @@ -453,7 +455,7 @@ public static bool TryParse([CanBeNull] string str, out ForceChangeRate result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ForceChangeRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out ForceChangeRate result) { return QuantityParser.Default.TryParse( str, @@ -486,7 +488,7 @@ public static ForceChangeRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ForceChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ForceChangeRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -507,7 +509,7 @@ public static bool TryParseUnit(string str, out ForceChangeRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ForceChangeRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ForceChangeRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -712,7 +714,7 @@ public double As(ForceChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -755,7 +757,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ForceChangeRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -855,7 +857,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -867,7 +869,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -882,7 +884,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -910,11 +912,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index e0f342908e..ad2286a663 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -102,7 +104,7 @@ public ForcePerLength(double value, ForcePerLengthUnit unit) /// No unit was found for the given . public ForcePerLength(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -320,7 +322,7 @@ public static string GetAbbreviation(ForcePerLengthUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ForcePerLengthUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ForcePerLengthUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -602,7 +604,7 @@ public static ForcePerLength Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ForcePerLength Parse(string str, [CanBeNull] IFormatProvider provider) + public static ForcePerLength Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -618,7 +620,7 @@ public static ForcePerLength Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ForcePerLength result) + public static bool TryParse(string? str, out ForcePerLength result) { return TryParse(str, null, out result); } @@ -633,7 +635,7 @@ public static bool TryParse([CanBeNull] string str, out ForcePerLength result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ForcePerLength result) + public static bool TryParse(string? str, IFormatProvider? provider, out ForcePerLength result) { return QuantityParser.Default.TryParse( str, @@ -666,7 +668,7 @@ public static ForcePerLengthUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ForcePerLengthUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ForcePerLengthUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -687,7 +689,7 @@ public static bool TryParseUnit(string str, out ForcePerLengthUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ForcePerLengthUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ForcePerLengthUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -892,7 +894,7 @@ public double As(ForcePerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -935,7 +937,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ForcePerLength ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1059,7 +1061,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1071,7 +1073,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1086,7 +1088,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1114,11 +1116,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs index 3965121cac..665f183951 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public Frequency(double value, FrequencyUnit unit) /// No unit was found for the given . public Frequency(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -242,7 +244,7 @@ public static string GetAbbreviation(FrequencyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(FrequencyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(FrequencyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -407,7 +409,7 @@ public static Frequency Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Frequency Parse(string str, [CanBeNull] IFormatProvider provider) + public static Frequency Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -423,7 +425,7 @@ public static Frequency Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Frequency result) + public static bool TryParse(string? str, out Frequency result) { return TryParse(str, null, out result); } @@ -438,7 +440,7 @@ public static bool TryParse([CanBeNull] string str, out Frequency result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Frequency result) + public static bool TryParse(string? str, IFormatProvider? provider, out Frequency result) { return QuantityParser.Default.TryParse( str, @@ -471,7 +473,7 @@ public static FrequencyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static FrequencyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static FrequencyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -492,7 +494,7 @@ public static bool TryParseUnit(string str, out FrequencyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out FrequencyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out FrequencyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -697,7 +699,7 @@ public double As(FrequencyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -740,7 +742,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Frequency ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -838,7 +840,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -850,7 +852,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -865,7 +867,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -893,11 +895,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs index 28e511767e..6fd8492a34 100644 --- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public FuelEfficiency(double value, FuelEfficiencyUnit unit) /// No unit was found for the given . public FuelEfficiency(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -209,7 +211,7 @@ public static string GetAbbreviation(FuelEfficiencyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(FuelEfficiencyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(FuelEfficiencyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -320,7 +322,7 @@ public static FuelEfficiency Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static FuelEfficiency Parse(string str, [CanBeNull] IFormatProvider provider) + public static FuelEfficiency Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -336,7 +338,7 @@ public static FuelEfficiency Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out FuelEfficiency result) + public static bool TryParse(string? str, out FuelEfficiency result) { return TryParse(str, null, out result); } @@ -351,7 +353,7 @@ public static bool TryParse([CanBeNull] string str, out FuelEfficiency result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out FuelEfficiency result) + public static bool TryParse(string? str, IFormatProvider? provider, out FuelEfficiency result) { return QuantityParser.Default.TryParse( str, @@ -384,7 +386,7 @@ public static FuelEfficiencyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static FuelEfficiencyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static FuelEfficiencyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -405,7 +407,7 @@ public static bool TryParseUnit(string str, out FuelEfficiencyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out FuelEfficiencyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out FuelEfficiencyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -610,7 +612,7 @@ public double As(FuelEfficiencyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -653,7 +655,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public FuelEfficiency ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -739,7 +741,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -751,7 +753,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -766,7 +768,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -794,11 +796,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs index 4ec5cdac79..06ec38a224 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -97,7 +99,7 @@ public HeatFlux(double value, HeatFluxUnit unit) /// No unit was found for the given . public HeatFlux(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -290,7 +292,7 @@ public static string GetAbbreviation(HeatFluxUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(HeatFluxUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(HeatFluxUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -527,7 +529,7 @@ public static HeatFlux Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static HeatFlux Parse(string str, [CanBeNull] IFormatProvider provider) + public static HeatFlux Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -543,7 +545,7 @@ public static HeatFlux Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out HeatFlux result) + public static bool TryParse(string? str, out HeatFlux result) { return TryParse(str, null, out result); } @@ -558,7 +560,7 @@ public static bool TryParse([CanBeNull] string str, out HeatFlux result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out HeatFlux result) + public static bool TryParse(string? str, IFormatProvider? provider, out HeatFlux result) { return QuantityParser.Default.TryParse( str, @@ -591,7 +593,7 @@ public static HeatFluxUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static HeatFluxUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static HeatFluxUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -612,7 +614,7 @@ public static bool TryParseUnit(string str, out HeatFluxUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out HeatFluxUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatFluxUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -817,7 +819,7 @@ public double As(HeatFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -860,7 +862,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public HeatFlux ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -974,7 +976,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -986,7 +988,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1001,7 +1003,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1029,11 +1031,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index ebd5b931f1..346bd88420 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// No unit was found for the given . public HeatTransferCoefficient(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(HeatTransferCoefficientUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(HeatTransferCoefficientUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(HeatTransferCoefficientUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static HeatTransferCoefficient Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static HeatTransferCoefficient Parse(string str, [CanBeNull] IFormatProvider provider) + public static HeatTransferCoefficient Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static HeatTransferCoefficient Parse(string str, [CanBeNull] IFormatProvi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out HeatTransferCoefficient result) + public static bool TryParse(string? str, out HeatTransferCoefficient result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out HeatTransferCoefficient /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out HeatTransferCoefficient result) + public static bool TryParse(string? str, IFormatProvider? provider, out HeatTransferCoefficient result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static HeatTransferCoefficientUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static HeatTransferCoefficientUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static HeatTransferCoefficientUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out HeatTransferCoefficientUnit unit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out HeatTransferCoefficientUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatTransferCoefficientUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(HeatTransferCoefficientUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public HeatTransferCoefficient ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs index f07f5051ba..d18c6d8b5a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public Illuminance(double value, IlluminanceUnit unit) /// No unit was found for the given . public Illuminance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -209,7 +211,7 @@ public static string GetAbbreviation(IlluminanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(IlluminanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(IlluminanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -320,7 +322,7 @@ public static Illuminance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Illuminance Parse(string str, [CanBeNull] IFormatProvider provider) + public static Illuminance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -336,7 +338,7 @@ public static Illuminance Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Illuminance result) + public static bool TryParse(string? str, out Illuminance result) { return TryParse(str, null, out result); } @@ -351,7 +353,7 @@ public static bool TryParse([CanBeNull] string str, out Illuminance result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Illuminance result) + public static bool TryParse(string? str, IFormatProvider? provider, out Illuminance result) { return QuantityParser.Default.TryParse( str, @@ -384,7 +386,7 @@ public static IlluminanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static IlluminanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static IlluminanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -405,7 +407,7 @@ public static bool TryParseUnit(string str, out IlluminanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out IlluminanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out IlluminanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -610,7 +612,7 @@ public double As(IlluminanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -653,7 +655,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Illuminance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -739,7 +741,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -751,7 +753,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -766,7 +768,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -794,11 +796,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs index 88e5dea32a..978d41bbbc 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -105,7 +107,7 @@ public Information(decimal value, InformationUnit unit) /// No unit was found for the given . public Information(decimal value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -340,7 +342,7 @@ public static string GetAbbreviation(InformationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(InformationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(InformationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -649,7 +651,7 @@ public static Information Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Information Parse(string str, [CanBeNull] IFormatProvider provider) + public static Information Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -665,7 +667,7 @@ public static Information Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Information result) + public static bool TryParse(string? str, out Information result) { return TryParse(str, null, out result); } @@ -680,7 +682,7 @@ public static bool TryParse([CanBeNull] string str, out Information result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Information result) + public static bool TryParse(string? str, IFormatProvider? provider, out Information result) { return QuantityParser.Default.TryParse( str, @@ -713,7 +715,7 @@ public static InformationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static InformationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static InformationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -734,7 +736,7 @@ public static bool TryParseUnit(string str, out InformationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out InformationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out InformationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -939,7 +941,7 @@ public double As(InformationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -982,7 +984,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Information ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1112,7 +1114,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1124,7 +1126,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1139,7 +1141,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1167,11 +1169,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs index c091096522..d6c42f7d9d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -93,7 +95,7 @@ public Irradiance(double value, IrradianceUnit unit) /// No unit was found for the given . public Irradiance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -266,7 +268,7 @@ public static string GetAbbreviation(IrradianceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(IrradianceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(IrradianceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -467,7 +469,7 @@ public static Irradiance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Irradiance Parse(string str, [CanBeNull] IFormatProvider provider) + public static Irradiance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -483,7 +485,7 @@ public static Irradiance Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Irradiance result) + public static bool TryParse(string? str, out Irradiance result) { return TryParse(str, null, out result); } @@ -498,7 +500,7 @@ public static bool TryParse([CanBeNull] string str, out Irradiance result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Irradiance result) + public static bool TryParse(string? str, IFormatProvider? provider, out Irradiance result) { return QuantityParser.Default.TryParse( str, @@ -531,7 +533,7 @@ public static IrradianceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static IrradianceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static IrradianceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -552,7 +554,7 @@ public static bool TryParseUnit(string str, out IrradianceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out IrradianceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out IrradianceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -757,7 +759,7 @@ public double As(IrradianceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -800,7 +802,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Irradiance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -906,7 +908,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -918,7 +920,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -933,7 +935,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -961,11 +963,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs index 4bc0411db9..aaa98eb2d5 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public Irradiation(double value, IrradiationUnit unit) /// No unit was found for the given . public Irradiation(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -227,7 +229,7 @@ public static string GetAbbreviation(IrradiationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(IrradiationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(IrradiationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -365,7 +367,7 @@ public static Irradiation Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Irradiation Parse(string str, [CanBeNull] IFormatProvider provider) + public static Irradiation Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -381,7 +383,7 @@ public static Irradiation Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Irradiation result) + public static bool TryParse(string? str, out Irradiation result) { return TryParse(str, null, out result); } @@ -396,7 +398,7 @@ public static bool TryParse([CanBeNull] string str, out Irradiation result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Irradiation result) + public static bool TryParse(string? str, IFormatProvider? provider, out Irradiation result) { return QuantityParser.Default.TryParse( str, @@ -429,7 +431,7 @@ public static IrradiationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static IrradiationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static IrradiationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -450,7 +452,7 @@ public static bool TryParseUnit(string str, out IrradiationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out IrradiationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out IrradiationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -655,7 +657,7 @@ public double As(IrradiationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -698,7 +700,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Irradiation ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -790,7 +792,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -802,7 +804,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -817,7 +819,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -845,11 +847,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index dea04acfbc..03d75963b2 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -90,7 +92,7 @@ public KinematicViscosity(double value, KinematicViscosityUnit unit) /// No unit was found for the given . public KinematicViscosity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -233,7 +235,7 @@ public static string GetAbbreviation(KinematicViscosityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(KinematicViscosityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(KinematicViscosityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -380,7 +382,7 @@ public static KinematicViscosity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static KinematicViscosity Parse(string str, [CanBeNull] IFormatProvider provider) + public static KinematicViscosity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -396,7 +398,7 @@ public static KinematicViscosity Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out KinematicViscosity result) + public static bool TryParse(string? str, out KinematicViscosity result) { return TryParse(str, null, out result); } @@ -411,7 +413,7 @@ public static bool TryParse([CanBeNull] string str, out KinematicViscosity resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out KinematicViscosity result) + public static bool TryParse(string? str, IFormatProvider? provider, out KinematicViscosity result) { return QuantityParser.Default.TryParse( str, @@ -444,7 +446,7 @@ public static KinematicViscosityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static KinematicViscosityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static KinematicViscosityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -465,7 +467,7 @@ public static bool TryParseUnit(string str, out KinematicViscosityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out KinematicViscosityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out KinematicViscosityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -670,7 +672,7 @@ public double As(KinematicViscosityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -713,7 +715,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public KinematicViscosity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -807,7 +809,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -819,7 +821,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -834,7 +836,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -862,11 +864,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs index 87a837abf3..7d2099b3f5 100644 --- a/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -80,7 +82,7 @@ public LapseRate(double value, LapseRateUnit unit) /// No unit was found for the given . public LapseRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -188,7 +190,7 @@ public static string GetAbbreviation(LapseRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LapseRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LapseRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -272,7 +274,7 @@ public static LapseRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static LapseRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static LapseRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -288,7 +290,7 @@ public static LapseRate Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out LapseRate result) + public static bool TryParse(string? str, out LapseRate result) { return TryParse(str, null, out result); } @@ -303,7 +305,7 @@ public static bool TryParse([CanBeNull] string str, out LapseRate result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LapseRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out LapseRate result) { return QuantityParser.Default.TryParse( str, @@ -336,7 +338,7 @@ public static LapseRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LapseRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LapseRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -357,7 +359,7 @@ public static bool TryParseUnit(string str, out LapseRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LapseRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LapseRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -562,7 +564,7 @@ public double As(LapseRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -605,7 +607,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public LapseRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -685,7 +687,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -697,7 +699,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -712,7 +714,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -740,11 +742,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 2e208f7c3d..c22db172d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -112,7 +114,7 @@ public Length(double value, LengthUnit unit) /// No unit was found for the given . public Length(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -380,7 +382,7 @@ public static string GetAbbreviation(LengthUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LengthUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LengthUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -752,7 +754,7 @@ public static Length Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Length Parse(string str, [CanBeNull] IFormatProvider provider) + public static Length Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -768,7 +770,7 @@ public static Length Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Length result) + public static bool TryParse(string? str, out Length result) { return TryParse(str, null, out result); } @@ -783,7 +785,7 @@ public static bool TryParse([CanBeNull] string str, out Length result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Length result) + public static bool TryParse(string? str, IFormatProvider? provider, out Length result) { return QuantityParser.Default.TryParse( str, @@ -816,7 +818,7 @@ public static LengthUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LengthUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LengthUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -837,7 +839,7 @@ public static bool TryParseUnit(string str, out LengthUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LengthUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LengthUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1042,7 +1044,7 @@ public double As(LengthUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1085,7 +1087,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Length ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1229,7 +1231,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1241,7 +1243,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1256,7 +1258,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1284,11 +1286,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs index 3bae838ac1..18af1e4ca9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -81,7 +83,7 @@ public Level(double value, LevelUnit unit) /// No unit was found for the given . public Level(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -194,7 +196,7 @@ public static string GetAbbreviation(LevelUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LevelUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LevelUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -287,7 +289,7 @@ public static Level Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Level Parse(string str, [CanBeNull] IFormatProvider provider) + public static Level Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -303,7 +305,7 @@ public static Level Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Level result) + public static bool TryParse(string? str, out Level result) { return TryParse(str, null, out result); } @@ -318,7 +320,7 @@ public static bool TryParse([CanBeNull] string str, out Level result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Level result) + public static bool TryParse(string? str, IFormatProvider? provider, out Level result) { return QuantityParser.Default.TryParse( str, @@ -351,7 +353,7 @@ public static LevelUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LevelUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LevelUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -372,7 +374,7 @@ public static bool TryParseUnit(string str, out LevelUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LevelUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LevelUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -585,7 +587,7 @@ public double As(LevelUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -628,7 +630,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Level ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -710,7 +712,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -722,7 +724,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -737,7 +739,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -765,11 +767,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs index 0d9e24d486..9b16f87531 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -96,7 +98,7 @@ public LinearDensity(double value, LinearDensityUnit unit) /// No unit was found for the given . public LinearDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -269,7 +271,7 @@ public static string GetAbbreviation(LinearDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LinearDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LinearDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -470,7 +472,7 @@ public static LinearDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static LinearDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static LinearDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -486,7 +488,7 @@ public static LinearDensity Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out LinearDensity result) + public static bool TryParse(string? str, out LinearDensity result) { return TryParse(str, null, out result); } @@ -501,7 +503,7 @@ public static bool TryParse([CanBeNull] string str, out LinearDensity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LinearDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out LinearDensity result) { return QuantityParser.Default.TryParse( str, @@ -534,7 +536,7 @@ public static LinearDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LinearDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LinearDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -555,7 +557,7 @@ public static bool TryParseUnit(string str, out LinearDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LinearDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LinearDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -760,7 +762,7 @@ public double As(LinearDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -803,7 +805,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public LinearDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -909,7 +911,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -921,7 +923,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -936,7 +938,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -964,11 +966,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs index a5de965729..82a4b2473d 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -107,7 +109,7 @@ public LinearPowerDensity(double value, LinearPowerDensityUnit unit) /// No unit was found for the given . public LinearPowerDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -335,7 +337,7 @@ public static string GetAbbreviation(LinearPowerDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LinearPowerDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LinearPowerDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -635,7 +637,7 @@ public static LinearPowerDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static LinearPowerDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static LinearPowerDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -651,7 +653,7 @@ public static LinearPowerDensity Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out LinearPowerDensity result) + public static bool TryParse(string? str, out LinearPowerDensity result) { return TryParse(str, null, out result); } @@ -666,7 +668,7 @@ public static bool TryParse([CanBeNull] string str, out LinearPowerDensity resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LinearPowerDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out LinearPowerDensity result) { return QuantityParser.Default.TryParse( str, @@ -699,7 +701,7 @@ public static LinearPowerDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LinearPowerDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LinearPowerDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -720,7 +722,7 @@ public static bool TryParseUnit(string str, out LinearPowerDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LinearPowerDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LinearPowerDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -925,7 +927,7 @@ public double As(LinearPowerDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -968,7 +970,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public LinearPowerDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1096,7 +1098,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1108,7 +1110,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1123,7 +1125,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1151,11 +1153,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs index 7c37d993eb..893315f5ad 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -96,7 +98,7 @@ public Luminosity(double value, LuminosityUnit unit) /// No unit was found for the given . public Luminosity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -269,7 +271,7 @@ public static string GetAbbreviation(LuminosityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LuminosityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LuminosityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -470,7 +472,7 @@ public static Luminosity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Luminosity Parse(string str, [CanBeNull] IFormatProvider provider) + public static Luminosity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -486,7 +488,7 @@ public static Luminosity Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Luminosity result) + public static bool TryParse(string? str, out Luminosity result) { return TryParse(str, null, out result); } @@ -501,7 +503,7 @@ public static bool TryParse([CanBeNull] string str, out Luminosity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Luminosity result) + public static bool TryParse(string? str, IFormatProvider? provider, out Luminosity result) { return QuantityParser.Default.TryParse( str, @@ -534,7 +536,7 @@ public static LuminosityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LuminosityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LuminosityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -555,7 +557,7 @@ public static bool TryParseUnit(string str, out LuminosityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LuminosityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LuminosityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -760,7 +762,7 @@ public double As(LuminosityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -803,7 +805,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Luminosity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -909,7 +911,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -921,7 +923,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -936,7 +938,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -964,11 +966,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs index 4c81e7d098..c0de33ed2c 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public LuminousFlux(double value, LuminousFluxUnit unit) /// No unit was found for the given . public LuminousFlux(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(LuminousFluxUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LuminousFluxUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LuminousFluxUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static LuminousFlux Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static LuminousFlux Parse(string str, [CanBeNull] IFormatProvider provider) + public static LuminousFlux Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static LuminousFlux Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out LuminousFlux result) + public static bool TryParse(string? str, out LuminousFlux result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out LuminousFlux result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LuminousFlux result) + public static bool TryParse(string? str, IFormatProvider? provider, out LuminousFlux result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static LuminousFluxUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LuminousFluxUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LuminousFluxUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out LuminousFluxUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LuminousFluxUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LuminousFluxUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(LuminousFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public LuminousFlux ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs index c63e99ab0c..bd25c55a5a 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public LuminousIntensity(double value, LuminousIntensityUnit unit) /// No unit was found for the given . public LuminousIntensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(LuminousIntensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(LuminousIntensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(LuminousIntensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static LuminousIntensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static LuminousIntensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static LuminousIntensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static LuminousIntensity Parse(string str, [CanBeNull] IFormatProvider pr /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out LuminousIntensity result) + public static bool TryParse(string? str, out LuminousIntensity result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out LuminousIntensity result /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LuminousIntensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out LuminousIntensity result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static LuminousIntensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static LuminousIntensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static LuminousIntensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out LuminousIntensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out LuminousIntensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out LuminousIntensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(LuminousIntensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public LuminousIntensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs index daa00c37db..7a54cac4c8 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public MagneticField(double value, MagneticFieldUnit unit) /// No unit was found for the given . public MagneticField(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -209,7 +211,7 @@ public static string GetAbbreviation(MagneticFieldUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MagneticFieldUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MagneticFieldUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -320,7 +322,7 @@ public static MagneticField Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MagneticField Parse(string str, [CanBeNull] IFormatProvider provider) + public static MagneticField Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -336,7 +338,7 @@ public static MagneticField Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MagneticField result) + public static bool TryParse(string? str, out MagneticField result) { return TryParse(str, null, out result); } @@ -351,7 +353,7 @@ public static bool TryParse([CanBeNull] string str, out MagneticField result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MagneticField result) + public static bool TryParse(string? str, IFormatProvider? provider, out MagneticField result) { return QuantityParser.Default.TryParse( str, @@ -384,7 +386,7 @@ public static MagneticFieldUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MagneticFieldUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MagneticFieldUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -405,7 +407,7 @@ public static bool TryParseUnit(string str, out MagneticFieldUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MagneticFieldUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MagneticFieldUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -610,7 +612,7 @@ public double As(MagneticFieldUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -653,7 +655,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MagneticField ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -739,7 +741,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -751,7 +753,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -766,7 +768,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -794,11 +796,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs index 4543262443..6a56f32260 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public MagneticFlux(double value, MagneticFluxUnit unit) /// No unit was found for the given . public MagneticFlux(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(MagneticFluxUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MagneticFluxUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MagneticFluxUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static MagneticFlux Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MagneticFlux Parse(string str, [CanBeNull] IFormatProvider provider) + public static MagneticFlux Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static MagneticFlux Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MagneticFlux result) + public static bool TryParse(string? str, out MagneticFlux result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out MagneticFlux result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MagneticFlux result) + public static bool TryParse(string? str, IFormatProvider? provider, out MagneticFlux result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static MagneticFluxUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MagneticFluxUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MagneticFluxUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out MagneticFluxUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MagneticFluxUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MagneticFluxUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(MagneticFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MagneticFlux ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs index 8c1351ebaf..c0aab8d7e2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public Magnetization(double value, MagnetizationUnit unit) /// No unit was found for the given . public Magnetization(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(MagnetizationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MagnetizationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MagnetizationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static Magnetization Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Magnetization Parse(string str, [CanBeNull] IFormatProvider provider) + public static Magnetization Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static Magnetization Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Magnetization result) + public static bool TryParse(string? str, out Magnetization result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out Magnetization result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Magnetization result) + public static bool TryParse(string? str, IFormatProvider? provider, out Magnetization result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static MagnetizationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MagnetizationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MagnetizationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out MagnetizationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MagnetizationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MagnetizationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(MagnetizationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Magnetization ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index e6c35f10fa..96ce9ba4e1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -104,7 +106,7 @@ public Mass(double value, MassUnit unit) /// No unit was found for the given . public Mass(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -332,7 +334,7 @@ public static string GetAbbreviation(MassUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -632,7 +634,7 @@ public static Mass Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Mass Parse(string str, [CanBeNull] IFormatProvider provider) + public static Mass Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -648,7 +650,7 @@ public static Mass Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Mass result) + public static bool TryParse(string? str, out Mass result) { return TryParse(str, null, out result); } @@ -663,7 +665,7 @@ public static bool TryParse([CanBeNull] string str, out Mass result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Mass result) + public static bool TryParse(string? str, IFormatProvider? provider, out Mass result) { return QuantityParser.Default.TryParse( str, @@ -696,7 +698,7 @@ public static MassUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -717,7 +719,7 @@ public static bool TryParseUnit(string str, out MassUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -922,7 +924,7 @@ public double As(MassUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -965,7 +967,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Mass ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1093,7 +1095,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1105,7 +1107,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1120,7 +1122,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1148,11 +1150,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index f0961eb4ad..ea9cb23ba5 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -122,7 +124,7 @@ public MassConcentration(double value, MassConcentrationUnit unit) /// No unit was found for the given . public MassConcentration(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -425,7 +427,7 @@ public static string GetAbbreviation(MassConcentrationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassConcentrationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassConcentrationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -860,7 +862,7 @@ public static MassConcentration Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MassConcentration Parse(string str, [CanBeNull] IFormatProvider provider) + public static MassConcentration Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -876,7 +878,7 @@ public static MassConcentration Parse(string str, [CanBeNull] IFormatProvider pr /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MassConcentration result) + public static bool TryParse(string? str, out MassConcentration result) { return TryParse(str, null, out result); } @@ -891,7 +893,7 @@ public static bool TryParse([CanBeNull] string str, out MassConcentration result /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassConcentration result) + public static bool TryParse(string? str, IFormatProvider? provider, out MassConcentration result) { return QuantityParser.Default.TryParse( str, @@ -924,7 +926,7 @@ public static MassConcentrationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassConcentrationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassConcentrationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -945,7 +947,7 @@ public static bool TryParseUnit(string str, out MassConcentrationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassConcentrationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassConcentrationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1150,7 +1152,7 @@ public double As(MassConcentrationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1193,7 +1195,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MassConcentration ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1351,7 +1353,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1363,7 +1365,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1378,7 +1380,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1406,11 +1408,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 6819d6a96a..cc95d72957 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -112,7 +114,7 @@ public MassFlow(double value, MassFlowUnit unit) /// No unit was found for the given . public MassFlow(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -380,7 +382,7 @@ public static string GetAbbreviation(MassFlowUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassFlowUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassFlowUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -752,7 +754,7 @@ public static MassFlow Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MassFlow Parse(string str, [CanBeNull] IFormatProvider provider) + public static MassFlow Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -768,7 +770,7 @@ public static MassFlow Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MassFlow result) + public static bool TryParse(string? str, out MassFlow result) { return TryParse(str, null, out result); } @@ -783,7 +785,7 @@ public static bool TryParse([CanBeNull] string str, out MassFlow result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassFlow result) + public static bool TryParse(string? str, IFormatProvider? provider, out MassFlow result) { return QuantityParser.Default.TryParse( str, @@ -816,7 +818,7 @@ public static MassFlowUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassFlowUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassFlowUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -837,7 +839,7 @@ public static bool TryParseUnit(string str, out MassFlowUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassFlowUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassFlowUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1042,7 +1044,7 @@ public double As(MassFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1085,7 +1087,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MassFlow ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1229,7 +1231,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1241,7 +1243,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1256,7 +1258,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1284,11 +1286,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 23c7d68268..cddac285fe 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -91,7 +93,7 @@ public MassFlux(double value, MassFluxUnit unit) /// No unit was found for the given . public MassFlux(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -254,7 +256,7 @@ public static string GetAbbreviation(MassFluxUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassFluxUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -437,7 +439,7 @@ public static MassFlux Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MassFlux Parse(string str, [CanBeNull] IFormatProvider provider) + public static MassFlux Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -453,7 +455,7 @@ public static MassFlux Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MassFlux result) + public static bool TryParse(string? str, out MassFlux result) { return TryParse(str, null, out result); } @@ -468,7 +470,7 @@ public static bool TryParse([CanBeNull] string str, out MassFlux result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassFlux result) + public static bool TryParse(string? str, IFormatProvider? provider, out MassFlux result) { return QuantityParser.Default.TryParse( str, @@ -501,7 +503,7 @@ public static MassFluxUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassFluxUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassFluxUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -522,7 +524,7 @@ public static bool TryParseUnit(string str, out MassFluxUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassFluxUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassFluxUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -727,7 +729,7 @@ public double As(MassFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -770,7 +772,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MassFlux ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -872,7 +874,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -884,7 +886,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -899,7 +901,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -927,11 +929,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs index 22ab031331..d600750a73 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -106,7 +108,7 @@ public MassFraction(double value, MassFractionUnit unit) /// No unit was found for the given . public MassFraction(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -329,7 +331,7 @@ public static string GetAbbreviation(MassFractionUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassFractionUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassFractionUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -620,7 +622,7 @@ public static MassFraction Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MassFraction Parse(string str, [CanBeNull] IFormatProvider provider) + public static MassFraction Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -636,7 +638,7 @@ public static MassFraction Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MassFraction result) + public static bool TryParse(string? str, out MassFraction result) { return TryParse(str, null, out result); } @@ -651,7 +653,7 @@ public static bool TryParse([CanBeNull] string str, out MassFraction result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassFraction result) + public static bool TryParse(string? str, IFormatProvider? provider, out MassFraction result) { return QuantityParser.Default.TryParse( str, @@ -684,7 +686,7 @@ public static MassFractionUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassFractionUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassFractionUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -705,7 +707,7 @@ public static bool TryParseUnit(string str, out MassFractionUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassFractionUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassFractionUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -910,7 +912,7 @@ public double As(MassFractionUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -953,7 +955,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MassFraction ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1079,7 +1081,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1091,7 +1093,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1106,7 +1108,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1134,11 +1136,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs index c5964e13bf..7c835aded4 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -107,7 +109,7 @@ public MassMomentOfInertia(double value, MassMomentOfInertiaUnit unit) /// No unit was found for the given . public MassMomentOfInertia(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -350,7 +352,7 @@ public static string GetAbbreviation(MassMomentOfInertiaUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MassMomentOfInertiaUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MassMomentOfInertiaUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -677,7 +679,7 @@ public static MassMomentOfInertia Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MassMomentOfInertia Parse(string str, [CanBeNull] IFormatProvider provider) + public static MassMomentOfInertia Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -693,7 +695,7 @@ public static MassMomentOfInertia Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MassMomentOfInertia result) + public static bool TryParse(string? str, out MassMomentOfInertia result) { return TryParse(str, null, out result); } @@ -708,7 +710,7 @@ public static bool TryParse([CanBeNull] string str, out MassMomentOfInertia resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassMomentOfInertia result) + public static bool TryParse(string? str, IFormatProvider? provider, out MassMomentOfInertia result) { return QuantityParser.Default.TryParse( str, @@ -741,7 +743,7 @@ public static MassMomentOfInertiaUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MassMomentOfInertiaUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MassMomentOfInertiaUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -762,7 +764,7 @@ public static bool TryParseUnit(string str, out MassMomentOfInertiaUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MassMomentOfInertiaUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MassMomentOfInertiaUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -967,7 +969,7 @@ public double As(MassMomentOfInertiaUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1010,7 +1012,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MassMomentOfInertia ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1144,7 +1146,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1156,7 +1158,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1171,7 +1173,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1199,11 +1201,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs index edbcbbc65d..e77db094c4 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public MolarEnergy(double value, MolarEnergyUnit unit) /// No unit was found for the given . public MolarEnergy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(MolarEnergyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MolarEnergyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MolarEnergyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static MolarEnergy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MolarEnergy Parse(string str, [CanBeNull] IFormatProvider provider) + public static MolarEnergy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static MolarEnergy Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MolarEnergy result) + public static bool TryParse(string? str, out MolarEnergy result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out MolarEnergy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MolarEnergy result) + public static bool TryParse(string? str, IFormatProvider? provider, out MolarEnergy result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static MolarEnergyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MolarEnergyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MolarEnergyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out MolarEnergyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MolarEnergyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MolarEnergyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(MolarEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MolarEnergy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs index 754ece1c49..0a174a328c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public MolarEntropy(double value, MolarEntropyUnit unit) /// No unit was found for the given . public MolarEntropy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(MolarEntropyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MolarEntropyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MolarEntropyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static MolarEntropy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MolarEntropy Parse(string str, [CanBeNull] IFormatProvider provider) + public static MolarEntropy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static MolarEntropy Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MolarEntropy result) + public static bool TryParse(string? str, out MolarEntropy result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out MolarEntropy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MolarEntropy result) + public static bool TryParse(string? str, IFormatProvider? provider, out MolarEntropy result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static MolarEntropyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MolarEntropyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MolarEntropyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out MolarEntropyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MolarEntropyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MolarEntropyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(MolarEntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MolarEntropy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index 87bc5d163f..afc0741065 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -91,7 +93,7 @@ public MolarMass(double value, MolarMassUnit unit) /// No unit was found for the given . public MolarMass(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -254,7 +256,7 @@ public static string GetAbbreviation(MolarMassUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MolarMassUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MolarMassUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -437,7 +439,7 @@ public static MolarMass Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static MolarMass Parse(string str, [CanBeNull] IFormatProvider provider) + public static MolarMass Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -453,7 +455,7 @@ public static MolarMass Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out MolarMass result) + public static bool TryParse(string? str, out MolarMass result) { return TryParse(str, null, out result); } @@ -468,7 +470,7 @@ public static bool TryParse([CanBeNull] string str, out MolarMass result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MolarMass result) + public static bool TryParse(string? str, IFormatProvider? provider, out MolarMass result) { return QuantityParser.Default.TryParse( str, @@ -501,7 +503,7 @@ public static MolarMassUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MolarMassUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MolarMassUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -522,7 +524,7 @@ public static bool TryParseUnit(string str, out MolarMassUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MolarMassUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MolarMassUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -727,7 +729,7 @@ public double As(MolarMassUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -770,7 +772,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public MolarMass ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -872,7 +874,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -884,7 +886,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -899,7 +901,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -927,11 +929,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index c9e315b909..441038cbae 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -90,7 +92,7 @@ public Molarity(double value, MolarityUnit unit) /// No unit was found for the given . public Molarity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -233,7 +235,7 @@ public static string GetAbbreviation(MolarityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(MolarityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(MolarityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -380,7 +382,7 @@ public static Molarity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Molarity Parse(string str, [CanBeNull] IFormatProvider provider) + public static Molarity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -396,7 +398,7 @@ public static Molarity Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Molarity result) + public static bool TryParse(string? str, out Molarity result) { return TryParse(str, null, out result); } @@ -411,7 +413,7 @@ public static bool TryParse([CanBeNull] string str, out Molarity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Molarity result) + public static bool TryParse(string? str, IFormatProvider? provider, out Molarity result) { return QuantityParser.Default.TryParse( str, @@ -444,7 +446,7 @@ public static MolarityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static MolarityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static MolarityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -465,7 +467,7 @@ public static bool TryParseUnit(string str, out MolarityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out MolarityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out MolarityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -670,7 +672,7 @@ public double As(MolarityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -713,7 +715,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Molarity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -807,7 +809,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -819,7 +821,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -834,7 +836,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -862,11 +864,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs index f75792d221..0c483a2e0b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public Permeability(double value, PermeabilityUnit unit) /// No unit was found for the given . public Permeability(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(PermeabilityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PermeabilityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PermeabilityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static Permeability Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Permeability Parse(string str, [CanBeNull] IFormatProvider provider) + public static Permeability Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static Permeability Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Permeability result) + public static bool TryParse(string? str, out Permeability result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out Permeability result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Permeability result) + public static bool TryParse(string? str, IFormatProvider? provider, out Permeability result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static PermeabilityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PermeabilityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PermeabilityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out PermeabilityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PermeabilityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PermeabilityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(PermeabilityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Permeability ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs index d1637927b8..22611dc34f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public Permittivity(double value, PermittivityUnit unit) /// No unit was found for the given . public Permittivity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(PermittivityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PermittivityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PermittivityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static Permittivity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Permittivity Parse(string str, [CanBeNull] IFormatProvider provider) + public static Permittivity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static Permittivity Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Permittivity result) + public static bool TryParse(string? str, out Permittivity result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out Permittivity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Permittivity result) + public static bool TryParse(string? str, IFormatProvider? provider, out Permittivity result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static PermittivityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PermittivityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PermittivityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out PermittivityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PermittivityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PermittivityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(PermittivityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Permittivity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index a9b761d28c..40e4f2b80d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -104,7 +106,7 @@ public Power(decimal value, PowerUnit unit) /// No unit was found for the given . public Power(decimal value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -334,7 +336,7 @@ public static string GetAbbreviation(PowerUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PowerUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PowerUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -634,7 +636,7 @@ public static Power Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Power Parse(string str, [CanBeNull] IFormatProvider provider) + public static Power Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -650,7 +652,7 @@ public static Power Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Power result) + public static bool TryParse(string? str, out Power result) { return TryParse(str, null, out result); } @@ -665,7 +667,7 @@ public static bool TryParse([CanBeNull] string str, out Power result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Power result) + public static bool TryParse(string? str, IFormatProvider? provider, out Power result) { return QuantityParser.Default.TryParse( str, @@ -698,7 +700,7 @@ public static PowerUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PowerUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PowerUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -719,7 +721,7 @@ public static bool TryParseUnit(string str, out PowerUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PowerUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PowerUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -924,7 +926,7 @@ public double As(PowerUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -967,7 +969,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Power ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1095,7 +1097,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1107,7 +1109,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1122,7 +1124,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1150,11 +1152,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs index e714622d6a..dc133e4b44 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -123,7 +125,7 @@ public PowerDensity(double value, PowerDensityUnit unit) /// No unit was found for the given . public PowerDensity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -446,7 +448,7 @@ public static string GetAbbreviation(PowerDensityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PowerDensityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PowerDensityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -917,7 +919,7 @@ public static PowerDensity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static PowerDensity Parse(string str, [CanBeNull] IFormatProvider provider) + public static PowerDensity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -933,7 +935,7 @@ public static PowerDensity Parse(string str, [CanBeNull] IFormatProvider provide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out PowerDensity result) + public static bool TryParse(string? str, out PowerDensity result) { return TryParse(str, null, out result); } @@ -948,7 +950,7 @@ public static bool TryParse([CanBeNull] string str, out PowerDensity result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out PowerDensity result) + public static bool TryParse(string? str, IFormatProvider? provider, out PowerDensity result) { return QuantityParser.Default.TryParse( str, @@ -981,7 +983,7 @@ public static PowerDensityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PowerDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PowerDensityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -1002,7 +1004,7 @@ public static bool TryParseUnit(string str, out PowerDensityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PowerDensityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PowerDensityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1207,7 +1209,7 @@ public double As(PowerDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1250,7 +1252,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public PowerDensity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1416,7 +1418,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1428,7 +1430,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1443,7 +1445,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1471,11 +1473,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs index c8acd1662d..9406f5e527 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -81,7 +83,7 @@ public PowerRatio(double value, PowerRatioUnit unit) /// No unit was found for the given . public PowerRatio(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -194,7 +196,7 @@ public static string GetAbbreviation(PowerRatioUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PowerRatioUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PowerRatioUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -287,7 +289,7 @@ public static PowerRatio Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static PowerRatio Parse(string str, [CanBeNull] IFormatProvider provider) + public static PowerRatio Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -303,7 +305,7 @@ public static PowerRatio Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out PowerRatio result) + public static bool TryParse(string? str, out PowerRatio result) { return TryParse(str, null, out result); } @@ -318,7 +320,7 @@ public static bool TryParse([CanBeNull] string str, out PowerRatio result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out PowerRatio result) + public static bool TryParse(string? str, IFormatProvider? provider, out PowerRatio result) { return QuantityParser.Default.TryParse( str, @@ -351,7 +353,7 @@ public static PowerRatioUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PowerRatioUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PowerRatioUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -372,7 +374,7 @@ public static bool TryParseUnit(string str, out PowerRatioUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PowerRatioUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PowerRatioUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -585,7 +587,7 @@ public double As(PowerRatioUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -628,7 +630,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public PowerRatio ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -710,7 +712,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -722,7 +724,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -737,7 +739,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -765,11 +767,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index 2b23dacf30..02efb5dda6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -121,7 +123,7 @@ public Pressure(double value, PressureUnit unit) /// No unit was found for the given . public Pressure(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -434,7 +436,7 @@ public static string GetAbbreviation(PressureUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PressureUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PressureUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -887,7 +889,7 @@ public static Pressure Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Pressure Parse(string str, [CanBeNull] IFormatProvider provider) + public static Pressure Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -903,7 +905,7 @@ public static Pressure Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Pressure result) + public static bool TryParse(string? str, out Pressure result) { return TryParse(str, null, out result); } @@ -918,7 +920,7 @@ public static bool TryParse([CanBeNull] string str, out Pressure result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Pressure result) + public static bool TryParse(string? str, IFormatProvider? provider, out Pressure result) { return QuantityParser.Default.TryParse( str, @@ -951,7 +953,7 @@ public static PressureUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PressureUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PressureUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -972,7 +974,7 @@ public static bool TryParseUnit(string str, out PressureUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PressureUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PressureUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1177,7 +1179,7 @@ public double As(PressureUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1220,7 +1222,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Pressure ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1382,7 +1384,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1394,7 +1396,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1409,7 +1411,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1437,11 +1439,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index d141c4dd0a..47a2a95a60 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public PressureChangeRate(double value, PressureChangeRateUnit unit) /// No unit was found for the given . public PressureChangeRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -224,7 +226,7 @@ public static string GetAbbreviation(PressureChangeRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(PressureChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(PressureChangeRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -362,7 +364,7 @@ public static PressureChangeRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static PressureChangeRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static PressureChangeRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -378,7 +380,7 @@ public static PressureChangeRate Parse(string str, [CanBeNull] IFormatProvider p /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out PressureChangeRate result) + public static bool TryParse(string? str, out PressureChangeRate result) { return TryParse(str, null, out result); } @@ -393,7 +395,7 @@ public static bool TryParse([CanBeNull] string str, out PressureChangeRate resul /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out PressureChangeRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out PressureChangeRate result) { return QuantityParser.Default.TryParse( str, @@ -426,7 +428,7 @@ public static PressureChangeRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static PressureChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static PressureChangeRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -447,7 +449,7 @@ public static bool TryParseUnit(string str, out PressureChangeRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out PressureChangeRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out PressureChangeRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -652,7 +654,7 @@ public double As(PressureChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -695,7 +697,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public PressureChangeRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -787,7 +789,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -799,7 +801,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -814,7 +816,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -842,11 +844,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index 8f950a9b2c..4a78e8b313 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -85,7 +87,7 @@ public Ratio(double value, RatioUnit unit) /// No unit was found for the given . public Ratio(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -218,7 +220,7 @@ public static string GetAbbreviation(RatioUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RatioUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RatioUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -347,7 +349,7 @@ public static Ratio Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Ratio Parse(string str, [CanBeNull] IFormatProvider provider) + public static Ratio Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -363,7 +365,7 @@ public static Ratio Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Ratio result) + public static bool TryParse(string? str, out Ratio result) { return TryParse(str, null, out result); } @@ -378,7 +380,7 @@ public static bool TryParse([CanBeNull] string str, out Ratio result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Ratio result) + public static bool TryParse(string? str, IFormatProvider? provider, out Ratio result) { return QuantityParser.Default.TryParse( str, @@ -411,7 +413,7 @@ public static RatioUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RatioUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RatioUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -432,7 +434,7 @@ public static bool TryParseUnit(string str, out RatioUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RatioUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RatioUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -637,7 +639,7 @@ public double As(RatioUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -680,7 +682,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Ratio ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -770,7 +772,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -782,7 +784,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -797,7 +799,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -825,11 +827,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index 1659c660f9..71f8f7652c 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -81,7 +83,7 @@ public RatioChangeRate(double value, RatioChangeRateUnit unit) /// No unit was found for the given . public RatioChangeRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -194,7 +196,7 @@ public static string GetAbbreviation(RatioChangeRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RatioChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RatioChangeRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -287,7 +289,7 @@ public static RatioChangeRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static RatioChangeRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static RatioChangeRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -303,7 +305,7 @@ public static RatioChangeRate Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out RatioChangeRate result) + public static bool TryParse(string? str, out RatioChangeRate result) { return TryParse(str, null, out result); } @@ -318,7 +320,7 @@ public static bool TryParse([CanBeNull] string str, out RatioChangeRate result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out RatioChangeRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out RatioChangeRate result) { return QuantityParser.Default.TryParse( str, @@ -351,7 +353,7 @@ public static RatioChangeRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RatioChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RatioChangeRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -372,7 +374,7 @@ public static bool TryParseUnit(string str, out RatioChangeRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RatioChangeRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RatioChangeRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -577,7 +579,7 @@ public double As(RatioChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -620,7 +622,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public RatioChangeRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -702,7 +704,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -714,7 +716,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -729,7 +731,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -757,11 +759,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs index 1fb9e9125d..f1a4e78f17 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public ReactiveEnergy(double value, ReactiveEnergyUnit unit) /// No unit was found for the given . public ReactiveEnergy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(ReactiveEnergyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ReactiveEnergyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ReactiveEnergyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static ReactiveEnergy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ReactiveEnergy Parse(string str, [CanBeNull] IFormatProvider provider) + public static ReactiveEnergy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static ReactiveEnergy Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ReactiveEnergy result) + public static bool TryParse(string? str, out ReactiveEnergy result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out ReactiveEnergy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ReactiveEnergy result) + public static bool TryParse(string? str, IFormatProvider? provider, out ReactiveEnergy result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static ReactiveEnergyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ReactiveEnergyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ReactiveEnergyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out ReactiveEnergyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ReactiveEnergyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ReactiveEnergyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(ReactiveEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ReactiveEnergy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs index ac71aca660..54cb0b2510 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public ReactivePower(double value, ReactivePowerUnit unit) /// No unit was found for the given . public ReactivePower(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -206,7 +208,7 @@ public static string GetAbbreviation(ReactivePowerUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ReactivePowerUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ReactivePowerUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -317,7 +319,7 @@ public static ReactivePower Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ReactivePower Parse(string str, [CanBeNull] IFormatProvider provider) + public static ReactivePower Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -333,7 +335,7 @@ public static ReactivePower Parse(string str, [CanBeNull] IFormatProvider provid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ReactivePower result) + public static bool TryParse(string? str, out ReactivePower result) { return TryParse(str, null, out result); } @@ -348,7 +350,7 @@ public static bool TryParse([CanBeNull] string str, out ReactivePower result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ReactivePower result) + public static bool TryParse(string? str, IFormatProvider? provider, out ReactivePower result) { return QuantityParser.Default.TryParse( str, @@ -381,7 +383,7 @@ public static ReactivePowerUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ReactivePowerUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ReactivePowerUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -402,7 +404,7 @@ public static bool TryParseUnit(string str, out ReactivePowerUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ReactivePowerUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ReactivePowerUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -607,7 +609,7 @@ public double As(ReactivePowerUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -650,7 +652,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ReactivePower ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -736,7 +738,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -748,7 +750,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -763,7 +765,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -791,11 +793,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs index 0e67b0ad9f..a509b07238 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public RotationalAcceleration(double value, RotationalAccelerationUnit unit) /// No unit was found for the given . public RotationalAcceleration(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -206,7 +208,7 @@ public static string GetAbbreviation(RotationalAccelerationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RotationalAccelerationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RotationalAccelerationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -317,7 +319,7 @@ public static RotationalAcceleration Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static RotationalAcceleration Parse(string str, [CanBeNull] IFormatProvider provider) + public static RotationalAcceleration Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -333,7 +335,7 @@ public static RotationalAcceleration Parse(string str, [CanBeNull] IFormatProvid /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out RotationalAcceleration result) + public static bool TryParse(string? str, out RotationalAcceleration result) { return TryParse(str, null, out result); } @@ -348,7 +350,7 @@ public static bool TryParse([CanBeNull] string str, out RotationalAcceleration r /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out RotationalAcceleration result) + public static bool TryParse(string? str, IFormatProvider? provider, out RotationalAcceleration result) { return QuantityParser.Default.TryParse( str, @@ -381,7 +383,7 @@ public static RotationalAccelerationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RotationalAccelerationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RotationalAccelerationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -402,7 +404,7 @@ public static bool TryParseUnit(string str, out RotationalAccelerationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RotationalAccelerationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RotationalAccelerationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -607,7 +609,7 @@ public double As(RotationalAccelerationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -650,7 +652,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public RotationalAcceleration ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -736,7 +738,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -748,7 +750,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -763,7 +765,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -791,11 +793,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index bd301b10b7..5b9a8a95c1 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -92,7 +94,7 @@ public RotationalSpeed(double value, RotationalSpeedUnit unit) /// No unit was found for the given . public RotationalSpeed(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -260,7 +262,7 @@ public static string GetAbbreviation(RotationalSpeedUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RotationalSpeedUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RotationalSpeedUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -452,7 +454,7 @@ public static RotationalSpeed Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static RotationalSpeed Parse(string str, [CanBeNull] IFormatProvider provider) + public static RotationalSpeed Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -468,7 +470,7 @@ public static RotationalSpeed Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out RotationalSpeed result) + public static bool TryParse(string? str, out RotationalSpeed result) { return TryParse(str, null, out result); } @@ -483,7 +485,7 @@ public static bool TryParse([CanBeNull] string str, out RotationalSpeed result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out RotationalSpeed result) + public static bool TryParse(string? str, IFormatProvider? provider, out RotationalSpeed result) { return QuantityParser.Default.TryParse( str, @@ -516,7 +518,7 @@ public static RotationalSpeedUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RotationalSpeedUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RotationalSpeedUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -537,7 +539,7 @@ public static bool TryParseUnit(string str, out RotationalSpeedUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RotationalSpeedUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RotationalSpeedUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -742,7 +744,7 @@ public double As(RotationalSpeedUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -785,7 +787,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public RotationalSpeed ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -889,7 +891,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -901,7 +903,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -916,7 +918,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -944,11 +946,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs index bcacbb2f50..390a8b8cab 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -112,7 +114,7 @@ public RotationalStiffness(double value, RotationalStiffnessUnit unit) /// No unit was found for the given . public RotationalStiffness(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -380,7 +382,7 @@ public static string GetAbbreviation(RotationalStiffnessUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RotationalStiffnessUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RotationalStiffnessUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -752,7 +754,7 @@ public static RotationalStiffness Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static RotationalStiffness Parse(string str, [CanBeNull] IFormatProvider provider) + public static RotationalStiffness Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -768,7 +770,7 @@ public static RotationalStiffness Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out RotationalStiffness result) + public static bool TryParse(string? str, out RotationalStiffness result) { return TryParse(str, null, out result); } @@ -783,7 +785,7 @@ public static bool TryParse([CanBeNull] string str, out RotationalStiffness resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out RotationalStiffness result) + public static bool TryParse(string? str, IFormatProvider? provider, out RotationalStiffness result) { return QuantityParser.Default.TryParse( str, @@ -816,7 +818,7 @@ public static RotationalStiffnessUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RotationalStiffnessUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RotationalStiffnessUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -837,7 +839,7 @@ public static bool TryParseUnit(string str, out RotationalStiffnessUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RotationalStiffnessUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RotationalStiffnessUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1042,7 +1044,7 @@ public double As(RotationalStiffnessUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1085,7 +1087,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public RotationalStiffness ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1229,7 +1231,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1241,7 +1243,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1256,7 +1258,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1284,11 +1286,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs index 003aa62c6e..01d17a8096 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public RotationalStiffnessPerLength(double value, RotationalStiffnessPerLengthUn /// No unit was found for the given . public RotationalStiffnessPerLength(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(RotationalStiffnessPerLengthUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(RotationalStiffnessPerLengthUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(RotationalStiffnessPerLengthUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static RotationalStiffnessPerLength Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static RotationalStiffnessPerLength Parse(string str, [CanBeNull] IFormatProvider provider) + public static RotationalStiffnessPerLength Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static RotationalStiffnessPerLength Parse(string str, [CanBeNull] IFormat /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out RotationalStiffnessPerLength result) + public static bool TryParse(string? str, out RotationalStiffnessPerLength result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out RotationalStiffnessPerLe /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out RotationalStiffnessPerLength result) + public static bool TryParse(string? str, IFormatProvider? provider, out RotationalStiffnessPerLength result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static RotationalStiffnessPerLengthUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static RotationalStiffnessPerLengthUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static RotationalStiffnessPerLengthUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out RotationalStiffnessPerLengthUnit /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out RotationalStiffnessPerLengthUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out RotationalStiffnessPerLengthUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(RotationalStiffnessPerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public RotationalStiffnessPerLength ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs index 04b227eef1..8ab2aad5ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -83,7 +85,7 @@ public SolidAngle(double value, SolidAngleUnit unit) /// No unit was found for the given . public SolidAngle(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -191,7 +193,7 @@ public static string GetAbbreviation(SolidAngleUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SolidAngleUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SolidAngleUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -275,7 +277,7 @@ public static SolidAngle Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static SolidAngle Parse(string str, [CanBeNull] IFormatProvider provider) + public static SolidAngle Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -291,7 +293,7 @@ public static SolidAngle Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out SolidAngle result) + public static bool TryParse(string? str, out SolidAngle result) { return TryParse(str, null, out result); } @@ -306,7 +308,7 @@ public static bool TryParse([CanBeNull] string str, out SolidAngle result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out SolidAngle result) + public static bool TryParse(string? str, IFormatProvider? provider, out SolidAngle result) { return QuantityParser.Default.TryParse( str, @@ -339,7 +341,7 @@ public static SolidAngleUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SolidAngleUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SolidAngleUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -360,7 +362,7 @@ public static bool TryParseUnit(string str, out SolidAngleUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SolidAngleUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SolidAngleUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -565,7 +567,7 @@ public double As(SolidAngleUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -608,7 +610,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public SolidAngle ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -688,7 +690,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -700,7 +702,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -715,7 +717,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -743,11 +745,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index 20a61c239b..621840c989 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -107,7 +109,7 @@ public SpecificEnergy(double value, SpecificEnergyUnit unit) /// No unit was found for the given . public SpecificEnergy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -335,7 +337,7 @@ public static string GetAbbreviation(SpecificEnergyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SpecificEnergyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SpecificEnergyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -635,7 +637,7 @@ public static SpecificEnergy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static SpecificEnergy Parse(string str, [CanBeNull] IFormatProvider provider) + public static SpecificEnergy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -651,7 +653,7 @@ public static SpecificEnergy Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out SpecificEnergy result) + public static bool TryParse(string? str, out SpecificEnergy result) { return TryParse(str, null, out result); } @@ -666,7 +668,7 @@ public static bool TryParse([CanBeNull] string str, out SpecificEnergy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out SpecificEnergy result) + public static bool TryParse(string? str, IFormatProvider? provider, out SpecificEnergy result) { return QuantityParser.Default.TryParse( str, @@ -699,7 +701,7 @@ public static SpecificEnergyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SpecificEnergyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SpecificEnergyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -720,7 +722,7 @@ public static bool TryParseUnit(string str, out SpecificEnergyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SpecificEnergyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SpecificEnergyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -925,7 +927,7 @@ public double As(SpecificEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -968,7 +970,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public SpecificEnergy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1096,7 +1098,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1108,7 +1110,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1123,7 +1125,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1151,11 +1153,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs index 09b8255e69..dfd71b9c55 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -88,7 +90,7 @@ public SpecificEntropy(double value, SpecificEntropyUnit unit) /// No unit was found for the given . public SpecificEntropy(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -236,7 +238,7 @@ public static string GetAbbreviation(SpecificEntropyUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SpecificEntropyUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SpecificEntropyUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -392,7 +394,7 @@ public static SpecificEntropy Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static SpecificEntropy Parse(string str, [CanBeNull] IFormatProvider provider) + public static SpecificEntropy Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -408,7 +410,7 @@ public static SpecificEntropy Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out SpecificEntropy result) + public static bool TryParse(string? str, out SpecificEntropy result) { return TryParse(str, null, out result); } @@ -423,7 +425,7 @@ public static bool TryParse([CanBeNull] string str, out SpecificEntropy result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out SpecificEntropy result) + public static bool TryParse(string? str, IFormatProvider? provider, out SpecificEntropy result) { return QuantityParser.Default.TryParse( str, @@ -456,7 +458,7 @@ public static SpecificEntropyUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SpecificEntropyUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SpecificEntropyUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -477,7 +479,7 @@ public static bool TryParseUnit(string str, out SpecificEntropyUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SpecificEntropyUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SpecificEntropyUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -682,7 +684,7 @@ public double As(SpecificEntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -725,7 +727,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public SpecificEntropy ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -821,7 +823,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -833,7 +835,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -848,7 +850,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -876,11 +878,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index b9dae762c0..ea543e12f3 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -82,7 +84,7 @@ public SpecificVolume(double value, SpecificVolumeUnit unit) /// No unit was found for the given . public SpecificVolume(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -200,7 +202,7 @@ public static string GetAbbreviation(SpecificVolumeUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SpecificVolumeUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SpecificVolumeUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -302,7 +304,7 @@ public static SpecificVolume Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static SpecificVolume Parse(string str, [CanBeNull] IFormatProvider provider) + public static SpecificVolume Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -318,7 +320,7 @@ public static SpecificVolume Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out SpecificVolume result) + public static bool TryParse(string? str, out SpecificVolume result) { return TryParse(str, null, out result); } @@ -333,7 +335,7 @@ public static bool TryParse([CanBeNull] string str, out SpecificVolume result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out SpecificVolume result) + public static bool TryParse(string? str, IFormatProvider? provider, out SpecificVolume result) { return QuantityParser.Default.TryParse( str, @@ -366,7 +368,7 @@ public static SpecificVolumeUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SpecificVolumeUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SpecificVolumeUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -387,7 +389,7 @@ public static bool TryParseUnit(string str, out SpecificVolumeUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SpecificVolumeUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SpecificVolumeUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -592,7 +594,7 @@ public double As(SpecificVolumeUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -635,7 +637,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public SpecificVolume ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -719,7 +721,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -731,7 +733,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -746,7 +748,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -774,11 +776,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs index bdc517521b..b54221b038 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -99,7 +101,7 @@ public SpecificWeight(double value, SpecificWeightUnit unit) /// No unit was found for the given . public SpecificWeight(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -287,7 +289,7 @@ public static string GetAbbreviation(SpecificWeightUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SpecificWeightUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SpecificWeightUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -515,7 +517,7 @@ public static SpecificWeight Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static SpecificWeight Parse(string str, [CanBeNull] IFormatProvider provider) + public static SpecificWeight Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -531,7 +533,7 @@ public static SpecificWeight Parse(string str, [CanBeNull] IFormatProvider provi /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out SpecificWeight result) + public static bool TryParse(string? str, out SpecificWeight result) { return TryParse(str, null, out result); } @@ -546,7 +548,7 @@ public static bool TryParse([CanBeNull] string str, out SpecificWeight result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out SpecificWeight result) + public static bool TryParse(string? str, IFormatProvider? provider, out SpecificWeight result) { return QuantityParser.Default.TryParse( str, @@ -579,7 +581,7 @@ public static SpecificWeightUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SpecificWeightUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SpecificWeightUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -600,7 +602,7 @@ public static bool TryParseUnit(string str, out SpecificWeightUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SpecificWeightUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SpecificWeightUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -805,7 +807,7 @@ public double As(SpecificWeightUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -848,7 +850,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public SpecificWeight ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -960,7 +962,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -972,7 +974,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -987,7 +989,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1015,11 +1017,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index 5016235775..12460402a7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -111,7 +113,7 @@ public Speed(double value, SpeedUnit unit) /// No unit was found for the given . public Speed(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -374,7 +376,7 @@ public static string GetAbbreviation(SpeedUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(SpeedUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(SpeedUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -737,7 +739,7 @@ public static Speed Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Speed Parse(string str, [CanBeNull] IFormatProvider provider) + public static Speed Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -753,7 +755,7 @@ public static Speed Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Speed result) + public static bool TryParse(string? str, out Speed result) { return TryParse(str, null, out result); } @@ -768,7 +770,7 @@ public static bool TryParse([CanBeNull] string str, out Speed result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Speed result) + public static bool TryParse(string? str, IFormatProvider? provider, out Speed result) { return QuantityParser.Default.TryParse( str, @@ -801,7 +803,7 @@ public static SpeedUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static SpeedUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static SpeedUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -822,7 +824,7 @@ public static bool TryParseUnit(string str, out SpeedUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out SpeedUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out SpeedUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1027,7 +1029,7 @@ public double As(SpeedUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1070,7 +1072,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Speed ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1212,7 +1214,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1224,7 +1226,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1239,7 +1241,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1267,11 +1269,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs index 26756fb2fd..457489ea95 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public Temperature(double value, TemperatureUnit unit) /// No unit was found for the given . public Temperature(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -242,7 +244,7 @@ public static string GetAbbreviation(TemperatureUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(TemperatureUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(TemperatureUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -407,7 +409,7 @@ public static Temperature Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Temperature Parse(string str, [CanBeNull] IFormatProvider provider) + public static Temperature Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -423,7 +425,7 @@ public static Temperature Parse(string str, [CanBeNull] IFormatProvider provider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Temperature result) + public static bool TryParse(string? str, out Temperature result) { return TryParse(str, null, out result); } @@ -438,7 +440,7 @@ public static bool TryParse([CanBeNull] string str, out Temperature result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Temperature result) + public static bool TryParse(string? str, IFormatProvider? provider, out Temperature result) { return QuantityParser.Default.TryParse( str, @@ -471,7 +473,7 @@ public static TemperatureUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static TemperatureUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static TemperatureUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -492,7 +494,7 @@ public static bool TryParseUnit(string str, out TemperatureUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out TemperatureUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out TemperatureUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -651,7 +653,7 @@ public double As(TemperatureUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -694,7 +696,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Temperature ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -792,7 +794,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -804,7 +806,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -819,7 +821,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -847,11 +849,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index ef6a2f6b47..d39c7fe412 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -89,7 +91,7 @@ public TemperatureChangeRate(double value, TemperatureChangeRateUnit unit) /// No unit was found for the given . public TemperatureChangeRate(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -242,7 +244,7 @@ public static string GetAbbreviation(TemperatureChangeRateUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(TemperatureChangeRateUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(TemperatureChangeRateUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -407,7 +409,7 @@ public static TemperatureChangeRate Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static TemperatureChangeRate Parse(string str, [CanBeNull] IFormatProvider provider) + public static TemperatureChangeRate Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -423,7 +425,7 @@ public static TemperatureChangeRate Parse(string str, [CanBeNull] IFormatProvide /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out TemperatureChangeRate result) + public static bool TryParse(string? str, out TemperatureChangeRate result) { return TryParse(str, null, out result); } @@ -438,7 +440,7 @@ public static bool TryParse([CanBeNull] string str, out TemperatureChangeRate re /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out TemperatureChangeRate result) + public static bool TryParse(string? str, IFormatProvider? provider, out TemperatureChangeRate result) { return QuantityParser.Default.TryParse( str, @@ -471,7 +473,7 @@ public static TemperatureChangeRateUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static TemperatureChangeRateUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static TemperatureChangeRateUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -492,7 +494,7 @@ public static bool TryParseUnit(string str, out TemperatureChangeRateUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out TemperatureChangeRateUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out TemperatureChangeRateUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -697,7 +699,7 @@ public double As(TemperatureChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -740,7 +742,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public TemperatureChangeRate ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -838,7 +840,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -850,7 +852,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -865,7 +867,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -893,11 +895,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index 3736a10db8..c848c80097 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -88,7 +90,7 @@ public TemperatureDelta(double value, TemperatureDeltaUnit unit) /// No unit was found for the given . public TemperatureDelta(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -236,7 +238,7 @@ public static string GetAbbreviation(TemperatureDeltaUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(TemperatureDeltaUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(TemperatureDeltaUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -392,7 +394,7 @@ public static TemperatureDelta Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static TemperatureDelta Parse(string str, [CanBeNull] IFormatProvider provider) + public static TemperatureDelta Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -408,7 +410,7 @@ public static TemperatureDelta Parse(string str, [CanBeNull] IFormatProvider pro /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out TemperatureDelta result) + public static bool TryParse(string? str, out TemperatureDelta result) { return TryParse(str, null, out result); } @@ -423,7 +425,7 @@ public static bool TryParse([CanBeNull] string str, out TemperatureDelta result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out TemperatureDelta result) + public static bool TryParse(string? str, IFormatProvider? provider, out TemperatureDelta result) { return QuantityParser.Default.TryParse( str, @@ -456,7 +458,7 @@ public static TemperatureDeltaUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static TemperatureDeltaUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static TemperatureDeltaUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -477,7 +479,7 @@ public static bool TryParseUnit(string str, out TemperatureDeltaUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out TemperatureDeltaUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out TemperatureDeltaUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -682,7 +684,7 @@ public double As(TemperatureDeltaUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -725,7 +727,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public TemperatureDelta ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -821,7 +823,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -833,7 +835,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -848,7 +850,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -876,11 +878,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs index d253dc1eb7..048426f900 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ThermalConductivity(double value, ThermalConductivityUnit unit) /// No unit was found for the given . public ThermalConductivity(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -197,7 +199,7 @@ public static string GetAbbreviation(ThermalConductivityUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ThermalConductivityUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ThermalConductivityUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -290,7 +292,7 @@ public static ThermalConductivity Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ThermalConductivity Parse(string str, [CanBeNull] IFormatProvider provider) + public static ThermalConductivity Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -306,7 +308,7 @@ public static ThermalConductivity Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ThermalConductivity result) + public static bool TryParse(string? str, out ThermalConductivity result) { return TryParse(str, null, out result); } @@ -321,7 +323,7 @@ public static bool TryParse([CanBeNull] string str, out ThermalConductivity resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ThermalConductivity result) + public static bool TryParse(string? str, IFormatProvider? provider, out ThermalConductivity result) { return QuantityParser.Default.TryParse( str, @@ -354,7 +356,7 @@ public static ThermalConductivityUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ThermalConductivityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ThermalConductivityUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -375,7 +377,7 @@ public static bool TryParseUnit(string str, out ThermalConductivityUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ThermalConductivityUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ThermalConductivityUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -580,7 +582,7 @@ public double As(ThermalConductivityUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -623,7 +625,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ThermalConductivity ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -705,7 +707,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -717,7 +719,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -732,7 +734,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -760,11 +762,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs index e86109f59d..4f415cffc9 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -84,7 +86,7 @@ public ThermalResistance(double value, ThermalResistanceUnit unit) /// No unit was found for the given . public ThermalResistance(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -212,7 +214,7 @@ public static string GetAbbreviation(ThermalResistanceUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ThermalResistanceUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(ThermalResistanceUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -332,7 +334,7 @@ public static ThermalResistance Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static ThermalResistance Parse(string str, [CanBeNull] IFormatProvider provider) + public static ThermalResistance Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -348,7 +350,7 @@ public static ThermalResistance Parse(string str, [CanBeNull] IFormatProvider pr /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out ThermalResistance result) + public static bool TryParse(string? str, out ThermalResistance result) { return TryParse(str, null, out result); } @@ -363,7 +365,7 @@ public static bool TryParse([CanBeNull] string str, out ThermalResistance result /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ThermalResistance result) + public static bool TryParse(string? str, IFormatProvider? provider, out ThermalResistance result) { return QuantityParser.Default.TryParse( str, @@ -396,7 +398,7 @@ public static ThermalResistanceUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static ThermalResistanceUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static ThermalResistanceUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -417,7 +419,7 @@ public static bool TryParseUnit(string str, out ThermalResistanceUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out ThermalResistanceUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out ThermalResistanceUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -622,7 +624,7 @@ public double As(ThermalResistanceUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -665,7 +667,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public ThermalResistance ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -753,7 +755,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -765,7 +767,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -780,7 +782,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -808,11 +810,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index 46e15adb3a..c34bd7af3b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -100,7 +102,7 @@ public Torque(double value, TorqueUnit unit) /// No unit was found for the given . public Torque(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -308,7 +310,7 @@ public static string GetAbbreviation(TorqueUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(TorqueUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(TorqueUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -572,7 +574,7 @@ public static Torque Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Torque Parse(string str, [CanBeNull] IFormatProvider provider) + public static Torque Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -588,7 +590,7 @@ public static Torque Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Torque result) + public static bool TryParse(string? str, out Torque result) { return TryParse(str, null, out result); } @@ -603,7 +605,7 @@ public static bool TryParse([CanBeNull] string str, out Torque result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Torque result) + public static bool TryParse(string? str, IFormatProvider? provider, out Torque result) { return QuantityParser.Default.TryParse( str, @@ -636,7 +638,7 @@ public static TorqueUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static TorqueUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static TorqueUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -657,7 +659,7 @@ public static bool TryParseUnit(string str, out TorqueUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out TorqueUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out TorqueUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -862,7 +864,7 @@ public double As(TorqueUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -905,7 +907,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Torque ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1025,7 +1027,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1037,7 +1039,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1052,7 +1054,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1080,11 +1082,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs index 86ad2e3354..a3cc53ac38 100644 --- a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -100,7 +102,7 @@ public TorquePerLength(double value, TorquePerLengthUnit unit) /// No unit was found for the given . public TorquePerLength(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -308,7 +310,7 @@ public static string GetAbbreviation(TorquePerLengthUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(TorquePerLengthUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(TorquePerLengthUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -572,7 +574,7 @@ public static TorquePerLength Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static TorquePerLength Parse(string str, [CanBeNull] IFormatProvider provider) + public static TorquePerLength Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -588,7 +590,7 @@ public static TorquePerLength Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out TorquePerLength result) + public static bool TryParse(string? str, out TorquePerLength result) { return TryParse(str, null, out result); } @@ -603,7 +605,7 @@ public static bool TryParse([CanBeNull] string str, out TorquePerLength result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out TorquePerLength result) + public static bool TryParse(string? str, IFormatProvider? provider, out TorquePerLength result) { return QuantityParser.Default.TryParse( str, @@ -636,7 +638,7 @@ public static TorquePerLengthUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static TorquePerLengthUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static TorquePerLengthUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -657,7 +659,7 @@ public static bool TryParseUnit(string str, out TorquePerLengthUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out TorquePerLengthUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out TorquePerLengthUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -862,7 +864,7 @@ public double As(TorquePerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -905,7 +907,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public TorquePerLength ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1025,7 +1027,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1037,7 +1039,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1052,7 +1054,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1080,11 +1082,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs index a6e2a5e142..1389e35218 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -80,7 +82,7 @@ public VitaminA(double value, VitaminAUnit unit) /// No unit was found for the given . public VitaminA(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -188,7 +190,7 @@ public static string GetAbbreviation(VitaminAUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(VitaminAUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(VitaminAUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -272,7 +274,7 @@ public static VitaminA Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static VitaminA Parse(string str, [CanBeNull] IFormatProvider provider) + public static VitaminA Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -288,7 +290,7 @@ public static VitaminA Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out VitaminA result) + public static bool TryParse(string? str, out VitaminA result) { return TryParse(str, null, out result); } @@ -303,7 +305,7 @@ public static bool TryParse([CanBeNull] string str, out VitaminA result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out VitaminA result) + public static bool TryParse(string? str, IFormatProvider? provider, out VitaminA result) { return QuantityParser.Default.TryParse( str, @@ -336,7 +338,7 @@ public static VitaminAUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static VitaminAUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static VitaminAUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -357,7 +359,7 @@ public static bool TryParseUnit(string str, out VitaminAUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out VitaminAUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out VitaminAUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -562,7 +564,7 @@ public double As(VitaminAUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -605,7 +607,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public VitaminA ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -685,7 +687,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -697,7 +699,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -712,7 +714,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -740,11 +742,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index fbe1f2febf..3772fe9c9a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -129,7 +131,7 @@ public Volume(double value, VolumeUnit unit) /// No unit was found for the given . public Volume(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -482,7 +484,7 @@ public static string GetAbbreviation(VolumeUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(VolumeUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(VolumeUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -1007,7 +1009,7 @@ public static Volume Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static Volume Parse(string str, [CanBeNull] IFormatProvider provider) + public static Volume Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -1023,7 +1025,7 @@ public static Volume Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out Volume result) + public static bool TryParse(string? str, out Volume result) { return TryParse(str, null, out result); } @@ -1038,7 +1040,7 @@ public static bool TryParse([CanBeNull] string str, out Volume result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Volume result) + public static bool TryParse(string? str, IFormatProvider? provider, out Volume result) { return QuantityParser.Default.TryParse( str, @@ -1071,7 +1073,7 @@ public static VolumeUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static VolumeUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static VolumeUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -1092,7 +1094,7 @@ public static bool TryParseUnit(string str, out VolumeUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out VolumeUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out VolumeUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1297,7 +1299,7 @@ public double As(VolumeUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1340,7 +1342,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public Volume ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1518,7 +1520,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1530,7 +1532,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1545,7 +1547,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1573,11 +1575,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs index ba2b5cf025..0a8e0c65ae 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -102,7 +104,7 @@ public VolumeConcentration(double value, VolumeConcentrationUnit unit) /// No unit was found for the given . public VolumeConcentration(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -305,7 +307,7 @@ public static string GetAbbreviation(VolumeConcentrationUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(VolumeConcentrationUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(VolumeConcentrationUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -560,7 +562,7 @@ public static VolumeConcentration Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static VolumeConcentration Parse(string str, [CanBeNull] IFormatProvider provider) + public static VolumeConcentration Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -576,7 +578,7 @@ public static VolumeConcentration Parse(string str, [CanBeNull] IFormatProvider /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out VolumeConcentration result) + public static bool TryParse(string? str, out VolumeConcentration result) { return TryParse(str, null, out result); } @@ -591,7 +593,7 @@ public static bool TryParse([CanBeNull] string str, out VolumeConcentration resu /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out VolumeConcentration result) + public static bool TryParse(string? str, IFormatProvider? provider, out VolumeConcentration result) { return QuantityParser.Default.TryParse( str, @@ -624,7 +626,7 @@ public static VolumeConcentrationUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static VolumeConcentrationUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static VolumeConcentrationUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -645,7 +647,7 @@ public static bool TryParseUnit(string str, out VolumeConcentrationUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out VolumeConcentrationUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out VolumeConcentrationUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -850,7 +852,7 @@ public double As(VolumeConcentrationUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -893,7 +895,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public VolumeConcentration ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1011,7 +1013,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1023,7 +1025,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1038,7 +1040,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1066,11 +1068,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index 920d10fcfa..6e9d42012a 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -128,7 +130,7 @@ public VolumeFlow(double value, VolumeFlowUnit unit) /// No unit was found for the given . public VolumeFlow(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -476,7 +478,7 @@ public static string GetAbbreviation(VolumeFlowUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(VolumeFlowUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(VolumeFlowUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -992,7 +994,7 @@ public static VolumeFlow Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static VolumeFlow Parse(string str, [CanBeNull] IFormatProvider provider) + public static VolumeFlow Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -1008,7 +1010,7 @@ public static VolumeFlow Parse(string str, [CanBeNull] IFormatProvider provider) /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out VolumeFlow result) + public static bool TryParse(string? str, out VolumeFlow result) { return TryParse(str, null, out result); } @@ -1023,7 +1025,7 @@ public static bool TryParse([CanBeNull] string str, out VolumeFlow result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out VolumeFlow result) + public static bool TryParse(string? str, IFormatProvider? provider, out VolumeFlow result) { return QuantityParser.Default.TryParse( str, @@ -1056,7 +1058,7 @@ public static VolumeFlowUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static VolumeFlowUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static VolumeFlowUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -1077,7 +1079,7 @@ public static bool TryParseUnit(string str, out VolumeFlowUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out VolumeFlowUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out VolumeFlowUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -1282,7 +1284,7 @@ public double As(VolumeFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1325,7 +1327,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public VolumeFlow ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -1501,7 +1503,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -1513,7 +1515,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -1528,7 +1530,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -1556,11 +1558,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs index 71188b7bbc..6efb549f0a 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs @@ -24,6 +24,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + // ReSharper disable once CheckNamespace namespace UnitsNet @@ -86,7 +88,7 @@ public VolumePerLength(double value, VolumePerLengthUnit unit) /// No unit was found for the given . public VolumePerLength(double value, UnitSystem unitSystem) { - if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); @@ -224,7 +226,7 @@ public static string GetAbbreviation(VolumePerLengthUnit unit) /// Unit to get abbreviation for. /// Unit abbreviation string. /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(VolumePerLengthUnit unit, [CanBeNull] IFormatProvider provider) + public static string GetAbbreviation(VolumePerLengthUnit unit, IFormatProvider? provider) { return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); } @@ -362,7 +364,7 @@ public static VolumePerLength Parse(string str) /// Units.NET exceptions from other exceptions. /// /// Format to use when parsing number and unit. Defaults to if null. - public static VolumePerLength Parse(string str, [CanBeNull] IFormatProvider provider) + public static VolumePerLength Parse(string str, IFormatProvider? provider) { return QuantityParser.Default.Parse( str, @@ -378,7 +380,7 @@ public static VolumePerLength Parse(string str, [CanBeNull] IFormatProvider prov /// /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// - public static bool TryParse([CanBeNull] string str, out VolumePerLength result) + public static bool TryParse(string? str, out VolumePerLength result) { return TryParse(str, null, out result); } @@ -393,7 +395,7 @@ public static bool TryParse([CanBeNull] string str, out VolumePerLength result) /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out VolumePerLength result) + public static bool TryParse(string? str, IFormatProvider? provider, out VolumePerLength result) { return QuantityParser.Default.TryParse( str, @@ -426,7 +428,7 @@ public static VolumePerLengthUnit ParseUnit(string str) /// /// The value of 'str' cannot be null. /// Error parsing string. - public static VolumePerLengthUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + public static VolumePerLengthUnit ParseUnit(string str, IFormatProvider? provider) { return UnitParser.Default.Parse(str, provider); } @@ -447,7 +449,7 @@ public static bool TryParseUnit(string str, out VolumePerLengthUnit unit) /// Length.TryParseUnit("m", new CultureInfo("en-US")); /// /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider provider, out VolumePerLengthUnit unit) + public static bool TryParseUnit(string str, IFormatProvider? provider, out VolumePerLengthUnit unit) { return UnitParser.Default.TryParse(str, provider, out unit); } @@ -652,7 +654,7 @@ public double As(VolumePerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -695,7 +697,7 @@ IQuantity IQuantity.ToUnit(Enum unit) /// public VolumePerLength ToUnit(UnitSystem unitSystem) { - if(unitSystem == null) + if(unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); @@ -787,7 +789,7 @@ public override string ToString() /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - public string ToString([CanBeNull] IFormatProvider provider) + public string ToString(IFormatProvider? provider) { return ToString("g", provider); } @@ -799,7 +801,7 @@ public string ToString([CanBeNull] IFormatProvider provider) /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) { var value = Convert.ToDouble(Value); var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); @@ -814,7 +816,7 @@ public string ToString([CanBeNull] IFormatProvider provider, int significantDigi /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) { if (format == null) throw new ArgumentNullException(nameof(format)); if (args == null) throw new ArgumentNullException(nameof(args)); @@ -842,11 +844,11 @@ public string ToString(string format) /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. /// /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. + /// Format to use for localization and number formatting. Defaults to if null. /// The string representation. - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string format, IFormatProvider? provider) { - return QuantityFormatter.Format(this, format, formatProvider); + return QuantityFormatter.Format(this, format, provider); } #endregion diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 4675003c8c..fb8ac656d4 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -23,6 +23,8 @@ using UnitsNet.InternalHelpers; using UnitsNet.Units; +#nullable enable + namespace UnitsNet { /// @@ -254,7 +256,7 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu /// Unit enum value. /// The resulting quantity if successful, otherwise default. /// True if successful with assigned the value, otherwise false. - public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantity) + public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity? quantity) { switch (unit) { @@ -577,7 +579,7 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit /// Quantity string representation, such as "1.5 kg". Must be compatible with given quantity type. /// The resulting quantity if successful, otherwise default. /// The parsed quantity. - public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type quantityType, string quantityString, out IQuantity quantity) + public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, string quantityString, out IQuantity? quantity) { quantity = default(IQuantity); diff --git a/UnitsNet/IQuantity.cs b/UnitsNet/IQuantity.cs index 60f522e93f..47526f35ca 100644 --- a/UnitsNet/IQuantity.cs +++ b/UnitsNet/IQuantity.cs @@ -74,7 +74,7 @@ public interface IQuantity : IFormattable /// /// String representation. /// Format to use for localization and number formatting. Defaults to if null. - string ToString([CanBeNull] IFormatProvider provider); + string ToString(IFormatProvider? provider); /// /// Get string representation of value and unit. @@ -83,7 +83,7 @@ public interface IQuantity : IFormattable /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] - string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix); + string ToString(IFormatProvider? provider, int significantDigitsAfterRadix); /// /// Get string representation of value and unit. @@ -93,7 +93,7 @@ public interface IQuantity : IFormattable /// String representation. /// Format to use for localization and number formatting. Defaults to if null. [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] - string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args); + string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args); } /// diff --git a/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs b/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs index 0232e43834..7fa3efac3b 100644 --- a/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs +++ b/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs @@ -41,7 +41,7 @@ internal PropertyInfo GetProperty(string name) internal IEnumerable GetDeclaredMethods() { - var t = _type.ToUniformType(); + UniformTypeInfo? t = _type.ToUniformType(); while (t != null) { #if NET40 || NET35 || NET20 || SILVERLIGHT diff --git a/UnitsNet/QuantityFormatter.cs b/UnitsNet/QuantityFormatter.cs index 782c2de23c..a949f3b3d9 100644 --- a/UnitsNet/QuantityFormatter.cs +++ b/UnitsNet/QuantityFormatter.cs @@ -34,7 +34,7 @@ public class QuantityFormatter /// "s4" would return "1.2345 m" if is 1.2345678. Trailing zeros are omitted. /// /// The string representation. - public static string Format(IQuantity quantity, string format, IFormatProvider formatProvider) + public static string Format(IQuantity quantity, string format, IFormatProvider? formatProvider) where TUnitType : Enum { formatProvider = formatProvider ?? CultureInfo.CurrentUICulture; diff --git a/UnitsNet/QuantityInfo.cs b/UnitsNet/QuantityInfo.cs index 2dcdd4cb21..dbcbd78c2f 100644 --- a/UnitsNet/QuantityInfo.cs +++ b/UnitsNet/QuantityInfo.cs @@ -48,7 +48,6 @@ public QuantityInfo(QuantityType quantityType, [NotNull] UnitInfo[] unitInfos, [ BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions)); Zero = zero ?? throw new ArgumentNullException(nameof(zero)); - Name = quantityType.ToString(); QuantityType = quantityType; UnitType = UnitEnumTypes.First(t => t.Name == $"{quantityType}Unit"); @@ -136,7 +135,7 @@ public QuantityInfo(QuantityType quantityType, [NotNull] UnitInfo[] unitInfos, [ /// More than one unit was found that is a subset of . public UnitInfo GetUnitInfoFor(BaseUnits baseUnits) { - if(baseUnits == null) + if(baseUnits is null) throw new ArgumentNullException(nameof(baseUnits)); var matchingUnitInfos = GetUnitInfosFor(baseUnits) @@ -161,7 +160,7 @@ public UnitInfo GetUnitInfoFor(BaseUnits baseUnits) /// is null. public IEnumerable GetUnitInfosFor(BaseUnits baseUnits) { - if(baseUnits == null) + if(baseUnits is null) throw new ArgumentNullException(nameof(baseUnits)); return UnitInfos.Where((unitInfo) => unitInfo.BaseUnits.IsSubsetOf(baseUnits)); @@ -185,6 +184,7 @@ public QuantityInfo(QuantityType quantityType, UnitInfo[] unitInfos, TUni Zero = zero; UnitInfos = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos)); BaseUnitInfo = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit)); + UnitType = baseUnit; // Obsolete members #pragma warning disable 618 diff --git a/UnitsNet/QuantityTypeConverter.cs b/UnitsNet/QuantityTypeConverter.cs index 712bd3fc79..d9d8988092 100644 --- a/UnitsNet/QuantityTypeConverter.cs +++ b/UnitsNet/QuantityTypeConverter.cs @@ -1,4 +1,4 @@ -// Licensed under MIT No Attribution, see LICENSE file at the root. +// Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; @@ -16,7 +16,7 @@ public abstract class UnitAttributeBase : Attribute /// /// The unit enum type, such as /// - public Enum UnitType { get; set; } + public Enum? UnitType { get; set; } /// /// Initializes a new instance of the class. @@ -125,7 +125,7 @@ public DisplayAsUnitAttribute(object unitType, string format = "") : base(unitTy /// Units.Length Length { get; set; } /// /// - public class QuantityTypeConverter : TypeConverter where TQuantity : IQuantity + public class QuantityTypeConverter : TypeConverter where TQuantity : struct, IQuantity { /// /// Returns true if sourceType if of type @@ -138,13 +138,12 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT return (sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType); } - private static TAttribute GetAttribute(ITypeDescriptorContext context) where TAttribute : UnitAttributeBase + private static TAttribute? GetAttribute(ITypeDescriptorContext? context) where TAttribute : UnitAttributeBase { - TAttribute attribute = null; - AttributeCollection ua = context?.PropertyDescriptor?.Attributes; - - attribute = (TAttribute)ua?[typeof(TAttribute)]; + if(context is null || context.PropertyDescriptor is null) + return null; + TAttribute? attribute = (TAttribute)context.PropertyDescriptor.Attributes[typeof(TAttribute)]; if (attribute != null) { QuantityType expected = default(TQuantity).Type; @@ -152,9 +151,7 @@ private static TAttribute GetAttribute(ITypeDescriptorContext contex if (attribute.UnitType != null) actual = Quantity.From(1, attribute.UnitType).Type; if (actual != QuantityType.Undefined && expected != actual) - { throw new ArgumentException($"The specified UnitType:'{attribute.UnitType}' dose not match QuantityType:'{expected}'"); - } } return attribute; @@ -171,30 +168,32 @@ private static TAttribute GetAttribute(ITypeDescriptorContext contex /// Unit value is not a know unit enum type. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - string stringValue = value as string; - object result = null; - - if (!string.IsNullOrEmpty(stringValue)) + if (value is string stringValue && !string.IsNullOrEmpty(stringValue)) { + IQuantity? quantity = null; + if (double.TryParse(stringValue, NumberStyles.Any, culture, out double dvalue)) { - DefaultUnitAttribute defaultUnit = GetAttribute(context) ?? new DefaultUnitAttribute(default(TQuantity).Unit); - - result = Quantity.From(dvalue, defaultUnit.UnitType); + var defaultUnit = GetAttribute(context) ?? new DefaultUnitAttribute(default(TQuantity).Unit); + if(defaultUnit.UnitType != null) + quantity = Quantity.From(dvalue, defaultUnit.UnitType); } else { - result = Quantity.Parse(culture, typeof(TQuantity), stringValue); + quantity = Quantity.Parse(culture, typeof(TQuantity), stringValue); } - ConvertToUnitAttribute convertToUnit = GetAttribute(context); - if (convertToUnit != null) + if( quantity != null ) { - result = ((IQuantity)result).ToUnit(convertToUnit.UnitType); + ConvertToUnitAttribute? convertToUnit = GetAttribute(context); + if (convertToUnit != null && convertToUnit.UnitType != null) + quantity = quantity.ToUnit(convertToUnit.UnitType); + + return quantity; } } - return result ?? base.ConvertFrom(context, culture, value); + return base.ConvertFrom(context, culture, value); } /// Returns true whether this converter can convert the to string, using the specified context. @@ -216,27 +215,17 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati /// The conversion cannot be performed. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - IQuantity qvalue = value as IQuantity; - object result = null; - DisplayAsUnitAttribute displayAsUnit = GetAttribute(context); + DisplayAsUnitAttribute? displayAsUnit = GetAttribute(context); - if (destinationType == typeof(string) && qvalue != null && displayAsUnit != null) + if (value is IQuantity qvalue && destinationType == typeof(string) && displayAsUnit != null) { if (displayAsUnit.UnitType != null) - { - result = qvalue.ToUnit(displayAsUnit.UnitType).ToString(displayAsUnit.Format, culture); - } + return qvalue.ToUnit(displayAsUnit.UnitType).ToString(displayAsUnit.Format, culture); else - { - result = qvalue.ToString(displayAsUnit.Format, culture); - } - } - else - { - result = base.ConvertTo(context, culture, value, destinationType); + return qvalue.ToString(displayAsUnit.Format, culture); } - return result; + return base.ConvertTo(context, culture, value, destinationType); } } } diff --git a/UnitsNet/UnitConverter.cs b/UnitsNet/UnitConverter.cs index b9641f03ce..781912cb36 100644 --- a/UnitsNet/UnitConverter.cs +++ b/UnitsNet/UnitConverter.cs @@ -252,12 +252,13 @@ public static double Convert(QuantityValue fromValue, Enum fromUnitValue, Enum t public static bool TryConvert(QuantityValue fromValue, Enum fromUnitValue, Enum toUnitValue, out double convertedValue) { convertedValue = 0; - if (!Quantity.TryFrom(fromValue, fromUnitValue, out IQuantity fromQuantity)) return false; + if (!Quantity.TryFrom(fromValue, fromUnitValue, out IQuantity? fromQuantity)) + return false; try { // We're not going to implement TryAs() in all quantities, so let's just try-catch here - convertedValue = fromQuantity.As(toUnitValue); + convertedValue = fromQuantity!.As(toUnitValue); return true; } catch @@ -296,24 +297,24 @@ public static bool TryConvert(QuantityValue fromValue, Enum fromUnitValue, Enum /// More than one unit matches the abbreviation. public static double ConvertByName(QuantityValue fromValue, string quantityName, string fromUnit, string toUnit) { - if (!TryGetUnitType(quantityName, out Type unitType)) + if (!TryGetUnitType(quantityName, out Type? unitType)) throw new UnitNotFoundException($"The unit type for the given quantity was not found: {quantityName}"); - if (!TryParseUnit(unitType, fromUnit, out Enum fromUnitValue)) // ex: LengthUnit.Meter + if (!TryParseUnit(unitType!, fromUnit, out Enum? fromUnitValue)) // ex: LengthUnit.Meter { var e = new UnitNotFoundException($"Unit not found [{fromUnit}]."); e.Data["unitName"] = fromUnit; throw e; } - if (!TryParseUnit(unitType, toUnit, out Enum toUnitValue)) // ex: LengthUnit.Centimeter + if (!TryParseUnit(unitType!, toUnit, out Enum? toUnitValue)) // ex: LengthUnit.Centimeter { var e = new UnitNotFoundException($"Unit not found [{toUnit}]."); e.Data["unitName"] = toUnit; throw e; } - return Convert(fromValue, fromUnitValue, toUnitValue); + return Convert(fromValue, fromUnitValue!, toUnitValue!); } /// @@ -347,16 +348,16 @@ public static bool TryConvertByName(QuantityValue inputValue, string quantityNam { result = 0d; - if (!TryGetUnitType(quantityName, out Type unitType)) + if (!TryGetUnitType(quantityName, out Type? unitType)) return false; - if (!TryParseUnit(unitType, fromUnit, out Enum fromUnitValue)) // ex: LengthUnit.Meter + if (!TryParseUnit(unitType!, fromUnit, out Enum? fromUnitValue)) // ex: LengthUnit.Meter return false; - if (!TryParseUnit(unitType, toUnit, out Enum toUnitValue)) // ex: LengthUnit.Centimeter + if (!TryParseUnit(unitType!, toUnit, out Enum? toUnitValue)) // ex: LengthUnit.Centimeter return false; - result = Convert(inputValue, fromUnitValue, toUnitValue); + result = Convert(inputValue, fromUnitValue!, toUnitValue!); return true; } @@ -423,17 +424,17 @@ public static double ConvertByAbbreviation(QuantityValue fromValue, string quant /// are mapped to the abbreviation. /// /// More than one unit matches the abbreviation. - public static double ConvertByAbbreviation(QuantityValue fromValue, string quantityName, string fromUnitAbbrev, string toUnitAbbrev, string culture) + public static double ConvertByAbbreviation(QuantityValue fromValue, string quantityName, string fromUnitAbbrev, string toUnitAbbrev, string? culture) { - if (!TryGetUnitType(quantityName, out Type unitType)) + if (!TryGetUnitType(quantityName, out Type? unitType)) throw new UnitNotFoundException($"The unit type for the given quantity was not found: {quantityName}"); var cultureInfo = string.IsNullOrWhiteSpace(culture) ? CultureInfo.CurrentUICulture : new CultureInfo(culture); - var fromUnit = UnitParser.Default.Parse(fromUnitAbbrev, unitType, cultureInfo); // ex: ("m", LengthUnit) => LengthUnit.Meter + var fromUnit = UnitParser.Default.Parse(fromUnitAbbrev, unitType!, cultureInfo); // ex: ("m", LengthUnit) => LengthUnit.Meter var fromQuantity = Quantity.From(fromValue, fromUnit); - var toUnit = UnitParser.Default.Parse(toUnitAbbrev, unitType, cultureInfo); // ex:("cm", LengthUnit) => LengthUnit.Centimeter + var toUnit = UnitParser.Default.Parse(toUnitAbbrev, unitType!, cultureInfo); // ex:("cm", LengthUnit) => LengthUnit.Centimeter return fromQuantity.As(toUnit); } @@ -498,23 +499,23 @@ public static bool TryConvertByAbbreviation(QuantityValue fromValue, string quan /// double centimeters = ConvertByName(5, "Length", "m", "cm"); // 500 /// True if conversion was successful. public static bool TryConvertByAbbreviation(QuantityValue fromValue, string quantityName, string fromUnitAbbrev, string toUnitAbbrev, out double result, - string culture) + string? culture) { result = 0d; - if (!TryGetUnitType(quantityName, out Type unitType)) + if (!TryGetUnitType(quantityName, out Type? unitType)) return false; var cultureInfo = string.IsNullOrWhiteSpace(culture) ? CultureInfo.CurrentUICulture : new CultureInfo(culture); - if (!UnitParser.Default.TryParse(fromUnitAbbrev, unitType, cultureInfo, out Enum fromUnit)) // ex: ("m", LengthUnit) => LengthUnit.Meter + if (!UnitParser.Default.TryParse(fromUnitAbbrev, unitType!, cultureInfo, out Enum? fromUnit)) // ex: ("m", LengthUnit) => LengthUnit.Meter return false; - if (!UnitParser.Default.TryParse(toUnitAbbrev, unitType, cultureInfo, out Enum toUnit)) // ex:("cm", LengthUnit) => LengthUnit.Centimeter + if (!UnitParser.Default.TryParse(toUnitAbbrev, unitType!, cultureInfo, out Enum? toUnit)) // ex:("cm", LengthUnit) => LengthUnit.Centimeter return false; - var fromQuantity = Quantity.From(fromValue, fromUnit); - result = fromQuantity.As(toUnit); + var fromQuantity = Quantity.From(fromValue, fromUnit!); + result = fromQuantity.As(toUnit!); return true; } @@ -527,7 +528,7 @@ public static bool TryConvertByAbbreviation(QuantityValue fromValue, string quan /// The return enum value, such as boxed as an object. /// True if succeeded, otherwise false. /// No unit values match the . - private static bool TryParseUnit(Type unitType, string unitName, out Enum unitValue) + private static bool TryParseUnit(Type unitType, string unitName, out Enum? unitValue) { unitValue = null; var eNames = Enum.GetNames(unitType); @@ -539,7 +540,7 @@ private static bool TryParseUnit(Type unitType, string unitName, out Enum unitVa return true; } - private static bool TryGetUnitType(string quantityName, out Type unitType) + private static bool TryGetUnitType(string quantityName, out Type? unitType) { var quantityInfo = Quantity.Infos.FirstOrDefault((info) => info.Name.Equals(quantityName, StringComparison.OrdinalIgnoreCase)); diff --git a/UnitsNet/UnitFormatter.cs b/UnitsNet/UnitFormatter.cs index 3e1259b718..b74eff72c6 100644 --- a/UnitsNet/UnitFormatter.cs +++ b/UnitsNet/UnitFormatter.cs @@ -71,7 +71,7 @@ private static bool NearlyEqual(double a, double b) /// The current culture. /// The list of format arguments. /// An array of ToString format arguments. - public static object[] GetFormatArgs(TUnitType unit, double value, [CanBeNull] IFormatProvider culture, IEnumerable args) + public static object[] GetFormatArgs(TUnitType unit, double value, IFormatProvider? culture, IEnumerable args) where TUnitType : Enum { string abbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(typeof(TUnitType), Convert.ToInt32(unit), culture); diff --git a/UnitsNet/UnitsNet.csproj b/UnitsNet/UnitsNet.csproj index 935f5b3cd5..bb93b156cc 100644 --- a/UnitsNet/UnitsNet.csproj +++ b/UnitsNet/UnitsNet.csproj @@ -21,6 +21,7 @@ 4.0.0.0 latest + enable UnitsNet netstandard2.0;net40 true diff --git a/appveyor.yml b/appveyor.yml index 166c0a8011..d12303c839 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: '{build}' -image: Visual Studio 2017 +image: Visual Studio 2019 # Don't build PR commits twice skip_branch_with_pr: true