Skip to content

Remove obsolete methods #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 28, 2018
  •  
  •  
  •  
87 changes: 2 additions & 85 deletions Common/GeneratedCode/Quantities/Acceleration.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,11 @@ static Acceleration()
BaseDimensions = new BaseDimensions(1, 0, -2, 0, 0, 0, 0);
}

/// <summary>
/// Creates the quantity with the given value in the base unit MeterPerSecondSquared.
/// </summary>
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public Acceleration(double meterspersecondsquared)
{
_value = Convert.ToDouble(meterspersecondsquared);
_unit = BaseUnit;
}

/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name="numericValue">Numeric value.</param>
/// <param name="unit">Unit representation.</param>
/// <param name="unit">The unit representation to contruct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
#if WINDOWS_UWP
private
Expand All @@ -109,33 +99,6 @@ public Acceleration(double meterspersecondsquared)
_unit = unit;
}

// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
/// <summary>
/// Creates the quantity with the given value assuming the base unit MeterPerSecondSquared.
/// </summary>
/// <param name="meterspersecondsquared">Value assuming base unit MeterPerSecondSquared.</param>
#if WINDOWS_UWP
private
#else
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public
#endif
Acceleration(long meterspersecondsquared) : this(Convert.ToDouble(meterspersecondsquared), BaseUnit) { }

// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
// Windows Runtime Component does not support decimal type
/// <summary>
/// Creates the quantity with the given value assuming the base unit MeterPerSecondSquared.
/// </summary>
/// <param name="meterspersecondsquared">Value assuming base unit MeterPerSecondSquared.</param>
#if WINDOWS_UWP
private
#else
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public
#endif
Acceleration(decimal meterspersecondsquared) : this(Convert.ToDouble(meterspersecondsquared), BaseUnit) { }

#region Properties

/// <summary>
Expand All @@ -144,7 +107,7 @@ public Acceleration(double meterspersecondsquared)
public static QuantityType QuantityType => QuantityType.Acceleration;

/// <summary>
/// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value.
/// The base unit of Acceleration, which is MeterPerSecondSquared. All conversions go via this value.
/// </summary>
public static AccelerationUnit BaseUnit => AccelerationUnit.MeterPerSecondSquared;

Expand Down Expand Up @@ -469,16 +432,6 @@ int CompareTo(Acceleration other)
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
}

[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals($quantityName, double, ComparisonType) to provide the max allowed absolute or relative error.")]
public override bool Equals(object obj)
{
if(obj is null || !(obj is Acceleration))
return false;

var objQuantity = (Acceleration)obj;
return _value.Equals(objQuantity.AsBaseNumericType(this.Unit));
}

/// <summary>
/// <para>
/// Compare equality to another Acceleration within the given absolute or relative tolerance.
Expand Down Expand Up @@ -530,20 +483,6 @@ public bool Equals(Acceleration other, double tolerance, ComparisonType comparis
return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
}

/// <summary>
/// Compare equality to another Acceleration by specifying a max allowed difference.
/// Note that it is advised against specifying zero difference, due to the nature
/// of floating point operations and using System.Double internally.
/// </summary>
/// <param name="other">Other quantity to compare to.</param>
/// <param name="maxError">Max error allowed.</param>
/// <returns>True if the difference between the two values is not greater than the specified max.</returns>
[Obsolete("Please use the Equals(Acceleration, double, ComparisonType) overload. This method will be removed in a future version.")]
public bool Equals(Acceleration other, Acceleration maxError)
{
return Math.Abs(_value - other.AsBaseNumericType(this.Unit)) <= maxError.AsBaseNumericType(this.Unit);
}

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
Expand Down Expand Up @@ -692,30 +631,8 @@ public static AccelerationUnit ParseUnit(string str)
return ParseUnit(str, (IFormatProvider)null);
}

/// <summary>
/// Parse a unit string.
/// </summary>
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
/// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="UnitSystem" />'s default culture.</param>
/// <example>
/// Length.ParseUnit("m", new CultureInfo("en-US"));
/// </example>
/// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
/// <exception cref="UnitsNetException">Error parsing string.</exception>
[Obsolete("Use overload that takes IFormatProvider instead of culture name. This method was only added to support WindowsRuntimeComponent and will be removed from other .NET targets.")]
public static AccelerationUnit ParseUnit(string str, [CanBeNull] string cultureName)
{
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
}

#endregion

/// <summary>
/// Set the default unit used by ToString(). Default is MeterPerSecondSquared
/// </summary>
[Obsolete("This is no longer used since we will instead use the quantity's Unit value as default.")]
public static AccelerationUnit ToStringDefaultUnit { get; set; } = AccelerationUnit.MeterPerSecondSquared;

/// <summary>
/// Get default string representation of value and unit.
/// </summary>
Expand Down
87 changes: 2 additions & 85 deletions Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,11 @@ static AmountOfSubstance()
BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 1, 0);
}

/// <summary>
/// Creates the quantity with the given value in the base unit Mole.
/// </summary>
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public AmountOfSubstance(double moles)
{
_value = Convert.ToDouble(moles);
_unit = BaseUnit;
}

/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name="numericValue">Numeric value.</param>
/// <param name="unit">Unit representation.</param>
/// <param name="unit">The unit representation to contruct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
#if WINDOWS_UWP
private
Expand All @@ -109,33 +99,6 @@ public AmountOfSubstance(double moles)
_unit = unit;
}

// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
/// <summary>
/// Creates the quantity with the given value assuming the base unit Mole.
/// </summary>
/// <param name="moles">Value assuming base unit Mole.</param>
#if WINDOWS_UWP
private
#else
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public
#endif
AmountOfSubstance(long moles) : this(Convert.ToDouble(moles), BaseUnit) { }

// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
// Windows Runtime Component does not support decimal type
/// <summary>
/// Creates the quantity with the given value assuming the base unit Mole.
/// </summary>
/// <param name="moles">Value assuming base unit Mole.</param>
#if WINDOWS_UWP
private
#else
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
public
#endif
AmountOfSubstance(decimal moles) : this(Convert.ToDouble(moles), BaseUnit) { }

#region Properties

/// <summary>
Expand All @@ -144,7 +107,7 @@ public AmountOfSubstance(double moles)
public static QuantityType QuantityType => QuantityType.AmountOfSubstance;

/// <summary>
/// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value.
/// The base unit of AmountOfSubstance, which is Mole. All conversions go via this value.
/// </summary>
public static AmountOfSubstanceUnit BaseUnit => AmountOfSubstanceUnit.Mole;

Expand Down Expand Up @@ -488,16 +451,6 @@ int CompareTo(AmountOfSubstance other)
return _value.CompareTo(other.AsBaseNumericType(this.Unit));
}

[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals($quantityName, double, ComparisonType) to provide the max allowed absolute or relative error.")]
public override bool Equals(object obj)
{
if(obj is null || !(obj is AmountOfSubstance))
return false;

var objQuantity = (AmountOfSubstance)obj;
return _value.Equals(objQuantity.AsBaseNumericType(this.Unit));
}

/// <summary>
/// <para>
/// Compare equality to another AmountOfSubstance within the given absolute or relative tolerance.
Expand Down Expand Up @@ -549,20 +502,6 @@ public bool Equals(AmountOfSubstance other, double tolerance, ComparisonType com
return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
}

/// <summary>
/// Compare equality to another AmountOfSubstance by specifying a max allowed difference.
/// Note that it is advised against specifying zero difference, due to the nature
/// of floating point operations and using System.Double internally.
/// </summary>
/// <param name="other">Other quantity to compare to.</param>
/// <param name="maxError">Max error allowed.</param>
/// <returns>True if the difference between the two values is not greater than the specified max.</returns>
[Obsolete("Please use the Equals(AmountOfSubstance, double, ComparisonType) overload. This method will be removed in a future version.")]
public bool Equals(AmountOfSubstance other, AmountOfSubstance maxError)
{
return Math.Abs(_value - other.AsBaseNumericType(this.Unit)) <= maxError.AsBaseNumericType(this.Unit);
}

/// <summary>
/// Returns the hash code for this instance.
/// </summary>
Expand Down Expand Up @@ -713,30 +652,8 @@ public static AmountOfSubstanceUnit ParseUnit(string str)
return ParseUnit(str, (IFormatProvider)null);
}

/// <summary>
/// Parse a unit string.
/// </summary>
/// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
/// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="UnitSystem" />'s default culture.</param>
/// <example>
/// Length.ParseUnit("m", new CultureInfo("en-US"));
/// </example>
/// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
/// <exception cref="UnitsNetException">Error parsing string.</exception>
[Obsolete("Use overload that takes IFormatProvider instead of culture name. This method was only added to support WindowsRuntimeComponent and will be removed from other .NET targets.")]
public static AmountOfSubstanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
{
return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
}

#endregion

/// <summary>
/// Set the default unit used by ToString(). Default is Mole
/// </summary>
[Obsolete("This is no longer used since we will instead use the quantity's Unit value as default.")]
public static AmountOfSubstanceUnit ToStringDefaultUnit { get; set; } = AmountOfSubstanceUnit.Mole;

/// <summary>
/// Get default string representation of value and unit.
/// </summary>
Expand Down
Loading