//******************************************************************************************************// Volume.cs - Gbtc//// Copyright © 2012, Grid Protection Alliance. All Rights Reserved.//// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See// the NOTICE file distributed with this work for additional information regarding copyright ownership.// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may// not use this file except in compliance with the License. You may obtain a copy of the License at://// http://www.opensource.org/licenses/MIT//// Unless agreed to in writing, the subject software distributed under the License is distributed on an// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the// License for the specific language governing permissions and limitations.//// Code Modification History:// ----------------------------------------------------------------------------------------------------// 01/25/2008 - J. Ritchie Carroll// Initial version of source generated.// 09/11/2008 - J. Ritchie Carroll// Converted to C#.// 08/10/2009 - Josh L. Patterson// Edited Comments.// 09/14/2009 - Stephen C. Wills// Added new header and license agreement.// 12/14/2012 - Starlynn Danyelle Gilliam// Modified Header.// 10/03/2017 - J. Ritchie Carroll// Added units enumeration with associated Convert method.////****************************************************************************************************** #region [ Contributor License Agreements ] /**************************************************************************\ Copyright © 2009 - J. Ritchie Carroll All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \**************************************************************************/ #endregion using System;using System.ComponentModel;using System.Globalization;using System.Runtime.CompilerServices; namespace GSF.Units{ #region [ Enumerations ] /// <summary> /// Represents the units available for a <see cref="Volume"/> value. /// </summary> public enum VolumeUnit { /// <summary> /// Cubic meter volume units. /// </summary> CubicMeters, /// <summary> /// Liter volume units. /// </summary> Liters, /// <summary> /// Teaspoon volume units. /// </summary> Teaspoons, /// <summary> /// Metric teaspoon volume units. /// </summary> MetricTeaspoons, /// <summary> /// Tablespoon volume units. /// </summary> Tablespoons, /// <summary> /// Metric tablespoon volume units. /// </summary> MetricTablespoons, /// <summary> /// Cup volume units. /// </summary> Cups, /// <summary> /// Metric cup volume units. /// </summary> MetricCups, /// <summary> /// Fluid ounce volume units. /// </summary> FluidOunces, /// <summary> /// Pint volume units. /// </summary> Pints, /// <summary> /// Quart volume units. /// </summary> Quarts, /// <summary> /// Gallon volume units. /// </summary> Gallons, /// <summary> /// Cubic inch volume units. /// </summary> CubicInches, /// <summary> /// Cubic feet volume units. /// </summary> CubicFeet } #endregion /// <summary> /// Represents a volume measurement, in cubic meters, as a double-precision floating-point number. /// </summary> /// <remarks> /// This class behaves just like a <see cref="double"/> representing a volume in cubic meters; it is implicitly /// castable to and from a <see cref="double"/> and therefore can be generally used "as" a double, but it /// has the advantage of handling conversions to and from other volume representations, specifically /// liters, teaspoons, tablespoons, cubic inches, fluid ounces, cups, pints, quarts, gallons and cubic feet. /// Metric conversions are handled simply by applying the needed <see cref="SI"/> conversion factor, for example: /// <example> /// Convert volume, in cubic meters, to cubic kilometers: /// <code> /// public double GetCubicKilometers(Volume cubicmeters) /// { /// return cubicmeters / SI.Kilo; /// } /// </code> /// This example converts teaspoons to cups: /// <code> /// public double GetCups(double teaspoons) /// { /// return Volume.FromTeaspoons(teaspoons).ToCups(); /// } /// </code> /// This example converts liters to fluid ounces: /// <code> /// public double GetFluidOunces(double liters) /// { /// return Volume.FromLiters(liters).ToFluidOunces(); /// } /// </code> /// </example> /// </remarks> [Serializable] public struct Volume : IComparable, IFormattable, IConvertible, IComparable<Volume>, IComparable<double>, IEquatable<Volume>, IEquatable<double> { #region [ Members ] // Constants private const double LitersFactor = 0.001D; private const double TeaspoonsFactor = 4.928921595e-6D; private const double MetricTeaspoonsFactor = 5.0e-6D; private const double TablespoonsFactor = 14.7867647825e-6D; private const double MetricTablespoonsFactor = 15.0e-6D; private const double CupsFactor = 236.5882365e-6D; private const double MetricCupsFactor = 250.0e-6D; private const double FluidOuncesFactor = 29.5735295625e-6D; private const double PintsFactor = 473.176473e-6D; private const double QuartsFactor = 946.352946e-6D; private const double GallonsFactor = 3.785411784e-3D; private const double CubicInchesFactor = 16.387064e-6D; private const double CubicFeetFactor = 0.028316846592D; // Fields private readonly double m_value; // Volume value stored in cubic meters #endregion #region [ Constructors ] /// <summary> /// Creates a new <see cref="Volume"/>. /// </summary> /// <param name="value">New volume value in cubic meters.</param> public Volume(double value) { m_value = value; } #endregion #region [ Methods ] /// <summary> /// Gets the <see cref="Volume"/> value in liters. /// </summary> /// <returns>Value of <see cref="Volume"/> in liters.</returns> public double ToLiters() { return m_value / LitersFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US teaspoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US teaspoons.</returns> public double ToTeaspoons() { return m_value / TeaspoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric teaspoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric teaspoons.</returns> public double ToMetricTeaspoons() { return m_value / MetricTeaspoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US tablespoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US tablespoons.</returns> public double ToTablespoons() { return m_value / TablespoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric tablespoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric tablespoons.</returns> public double ToMetricTablespoons() { return m_value / MetricTablespoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US cups. /// </summary> /// <returns>Value of <see cref="Volume"/> in US cups.</returns> public double ToCups() { return m_value / CupsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric cups. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric cups.</returns> public double ToMetricCups() { return m_value / MetricCupsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid ounces. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid ounces.</returns> public double ToFluidOunces() { return m_value / FluidOuncesFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid pints. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid pints.</returns> public double ToPints() { return m_value / PintsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid quarts. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid quarts.</returns> public double ToQuarts() { return m_value / QuartsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid gallons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid gallons.</returns> public double ToGallons() { return m_value / GallonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in cubic inches. /// </summary> /// <returns>Value of <see cref="Volume"/> in cubic inches.</returns> public double ToCubicInches() { return m_value / CubicInchesFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in cubic feet. /// </summary> /// <returns>Value of <see cref="Volume"/> in cubic feet.</returns> public double ToCubicFeet() { return m_value / CubicFeetFactor; } /// <summary> /// Converts the <see cref="Volume"/> to the specified <paramref name="targetUnit"/>. /// </summary> /// <param name="targetUnit">Target units.</param> /// <returns><see cref="Volume"/> converted to <paramref name="targetUnit"/>.</returns> public double ConvertTo(VolumeUnit targetUnit) { switch (targetUnit) { case VolumeUnit.CubicMeters: return m_value; case VolumeUnit.Liters: return ToLiters(); case VolumeUnit.Teaspoons: return ToTeaspoons(); case VolumeUnit.MetricTeaspoons: return ToMetricTeaspoons(); case VolumeUnit.Tablespoons: return ToTablespoons(); case VolumeUnit.MetricTablespoons: return ToMetricTablespoons(); case VolumeUnit.Cups: return ToCups(); case VolumeUnit.MetricCups: return ToMetricCups(); case VolumeUnit.FluidOunces: return ToFluidOunces(); case VolumeUnit.Pints: return ToPints(); case VolumeUnit.Quarts: return ToQuarts(); case VolumeUnit.Gallons: return ToGallons(); case VolumeUnit.CubicInches: return ToCubicInches(); case VolumeUnit.CubicFeet: return ToCubicFeet(); default: throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null); } } #region [ Numeric Interface Implementations ] /// <summary> /// Compares this instance to a specified object and returns an indication of their relative values. /// </summary> /// <param name="value">An object to compare, or null.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> /// <exception cref="ArgumentException">value is not a <see cref="Double"/> or <see cref="Volume"/>.</exception> public int CompareTo(object value) { if (value == null) return 1; double num; if (value is double) num = (double)value; else if (value is Volume) num = (Volume)value; else throw new ArgumentException("Argument must be a Double or a Volume"); return m_value < num ? -1 : (m_value > num ? 1 : 0); } /// <summary> /// Compares this instance to a specified <see cref="Volume"/> and returns an indication of their /// relative values. /// </summary> /// <param name="value">A <see cref="Volume"/> to compare.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> public int CompareTo(Volume value) { return CompareTo((double)value); } /// <summary> /// Compares this instance to a specified <see cref="Double"/> and returns an indication of their /// relative values. /// </summary> /// <param name="value">A <see cref="Double"/> to compare.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> public int CompareTo(double value) { return m_value < value ? -1 : (m_value > value ? 1 : 0); } /// <summary> /// Returns a value indicating whether this instance is equal to a specified object. /// </summary> /// <param name="obj">An object to compare, or null.</param> /// <returns> /// True if obj is an instance of <see cref="Double"/> or <see cref="Volume"/> and equals the value of this instance; /// otherwise, False. /// </returns> public override bool Equals(object obj) { if (obj is double) return Equals((double)obj); if (obj is Volume) return Equals((Volume)obj); return false; } /// <summary> /// Returns a value indicating whether this instance is equal to a specified <see cref="Volume"/> value. /// </summary> /// <param name="obj">A <see cref="Volume"/> value to compare to this instance.</param> /// <returns> /// True if obj has the same value as this instance; otherwise, False. /// </returns> public bool Equals(Volume obj) { return Equals((double)obj); } /// <summary> /// Returns a value indicating whether this instance is equal to a specified <see cref="Double"/> value. /// </summary> /// <param name="obj">A <see cref="Double"/> value to compare to this instance.</param> /// <returns> /// True if obj has the same value as this instance; otherwise, False. /// </returns> public bool Equals(double obj) { return m_value == obj; } /// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns> /// A 32-bit signed integer hash code. /// </returns> public override int GetHashCode() { return m_value.GetHashCode(); } /// <summary>Lines 1–500 of 1153. Load more
//****************************************************************************************************** // Volume.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 01/25/2008 - J. Ritchie Carroll // Initial version of source generated. // 09/11/2008 - J. Ritchie Carroll // Converted to C#. // 08/10/2009 - Josh L. Patterson // Edited Comments. // 09/14/2009 - Stephen C. Wills // Added new header and license agreement. // 12/14/2012 - Starlynn Danyelle Gilliam // Modified Header. // 10/03/2017 - J. Ritchie Carroll // Added units enumeration with associated Convert method. // //****************************************************************************************************** #region [ Contributor License Agreements ] /**************************************************************************\ Copyright © 2009 - J. Ritchie Carroll All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \**************************************************************************/ #endregion using System; using System.ComponentModel; using System.Globalization; using System.Runtime.CompilerServices; namespace GSF.Units { #region [ Enumerations ] /// <summary> /// Represents the units available for a <see cref="Volume"/> value. /// </summary> public enum VolumeUnit { /// <summary> /// Cubic meter volume units. /// </summary> CubicMeters, /// <summary> /// Liter volume units. /// </summary> Liters, /// <summary> /// Teaspoon volume units. /// </summary> Teaspoons, /// <summary> /// Metric teaspoon volume units. /// </summary> MetricTeaspoons, /// <summary> /// Tablespoon volume units. /// </summary> Tablespoons, /// <summary> /// Metric tablespoon volume units. /// </summary> MetricTablespoons, /// <summary> /// Cup volume units. /// </summary> Cups, /// <summary> /// Metric cup volume units. /// </summary> MetricCups, /// <summary> /// Fluid ounce volume units. /// </summary> FluidOunces, /// <summary> /// Pint volume units. /// </summary> Pints, /// <summary> /// Quart volume units. /// </summary> Quarts, /// <summary> /// Gallon volume units. /// </summary> Gallons, /// <summary> /// Cubic inch volume units. /// </summary> CubicInches, /// <summary> /// Cubic feet volume units. /// </summary> CubicFeet } #endregion /// <summary> /// Represents a volume measurement, in cubic meters, as a double-precision floating-point number. /// </summary> /// <remarks> /// This class behaves just like a <see cref="double"/> representing a volume in cubic meters; it is implicitly /// castable to and from a <see cref="double"/> and therefore can be generally used "as" a double, but it /// has the advantage of handling conversions to and from other volume representations, specifically /// liters, teaspoons, tablespoons, cubic inches, fluid ounces, cups, pints, quarts, gallons and cubic feet. /// Metric conversions are handled simply by applying the needed <see cref="SI"/> conversion factor, for example: /// <example> /// Convert volume, in cubic meters, to cubic kilometers: /// <code> /// public double GetCubicKilometers(Volume cubicmeters) /// { /// return cubicmeters / SI.Kilo; /// } /// </code> /// This example converts teaspoons to cups: /// <code> /// public double GetCups(double teaspoons) /// { /// return Volume.FromTeaspoons(teaspoons).ToCups(); /// } /// </code> /// This example converts liters to fluid ounces: /// <code> /// public double GetFluidOunces(double liters) /// { /// return Volume.FromLiters(liters).ToFluidOunces(); /// } /// </code> /// </example> /// </remarks> [Serializable] public struct Volume : IComparable, IFormattable, IConvertible, IComparable<Volume>, IComparable<double>, IEquatable<Volume>, IEquatable<double> { #region [ Members ] // Constants private const double LitersFactor = 0.001D; private const double TeaspoonsFactor = 4.928921595e-6D; private const double MetricTeaspoonsFactor = 5.0e-6D; private const double TablespoonsFactor = 14.7867647825e-6D; private const double MetricTablespoonsFactor = 15.0e-6D; private const double CupsFactor = 236.5882365e-6D; private const double MetricCupsFactor = 250.0e-6D; private const double FluidOuncesFactor = 29.5735295625e-6D; private const double PintsFactor = 473.176473e-6D; private const double QuartsFactor = 946.352946e-6D; private const double GallonsFactor = 3.785411784e-3D; private const double CubicInchesFactor = 16.387064e-6D; private const double CubicFeetFactor = 0.028316846592D; // Fields private readonly double m_value; // Volume value stored in cubic meters #endregion #region [ Constructors ] /// <summary> /// Creates a new <see cref="Volume"/>. /// </summary> /// <param name="value">New volume value in cubic meters.</param> public Volume(double value) { m_value = value; } #endregion #region [ Methods ] /// <summary> /// Gets the <see cref="Volume"/> value in liters. /// </summary> /// <returns>Value of <see cref="Volume"/> in liters.</returns> public double ToLiters() { return m_value / LitersFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US teaspoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US teaspoons.</returns> public double ToTeaspoons() { return m_value / TeaspoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric teaspoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric teaspoons.</returns> public double ToMetricTeaspoons() { return m_value / MetricTeaspoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US tablespoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US tablespoons.</returns> public double ToTablespoons() { return m_value / TablespoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric tablespoons. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric tablespoons.</returns> public double ToMetricTablespoons() { return m_value / MetricTablespoonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US cups. /// </summary> /// <returns>Value of <see cref="Volume"/> in US cups.</returns> public double ToCups() { return m_value / CupsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in metric cups. /// </summary> /// <returns>Value of <see cref="Volume"/> in metric cups.</returns> public double ToMetricCups() { return m_value / MetricCupsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid ounces. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid ounces.</returns> public double ToFluidOunces() { return m_value / FluidOuncesFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid pints. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid pints.</returns> public double ToPints() { return m_value / PintsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid quarts. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid quarts.</returns> public double ToQuarts() { return m_value / QuartsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in US fluid gallons. /// </summary> /// <returns>Value of <see cref="Volume"/> in US fluid gallons.</returns> public double ToGallons() { return m_value / GallonsFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in cubic inches. /// </summary> /// <returns>Value of <see cref="Volume"/> in cubic inches.</returns> public double ToCubicInches() { return m_value / CubicInchesFactor; } /// <summary> /// Gets the <see cref="Volume"/> value in cubic feet. /// </summary> /// <returns>Value of <see cref="Volume"/> in cubic feet.</returns> public double ToCubicFeet() { return m_value / CubicFeetFactor; } /// <summary> /// Converts the <see cref="Volume"/> to the specified <paramref name="targetUnit"/>. /// </summary> /// <param name="targetUnit">Target units.</param> /// <returns><see cref="Volume"/> converted to <paramref name="targetUnit"/>.</returns> public double ConvertTo(VolumeUnit targetUnit) { switch (targetUnit) { case VolumeUnit.CubicMeters: return m_value; case VolumeUnit.Liters: return ToLiters(); case VolumeUnit.Teaspoons: return ToTeaspoons(); case VolumeUnit.MetricTeaspoons: return ToMetricTeaspoons(); case VolumeUnit.Tablespoons: return ToTablespoons(); case VolumeUnit.MetricTablespoons: return ToMetricTablespoons(); case VolumeUnit.Cups: return ToCups(); case VolumeUnit.MetricCups: return ToMetricCups(); case VolumeUnit.FluidOunces: return ToFluidOunces(); case VolumeUnit.Pints: return ToPints(); case VolumeUnit.Quarts: return ToQuarts(); case VolumeUnit.Gallons: return ToGallons(); case VolumeUnit.CubicInches: return ToCubicInches(); case VolumeUnit.CubicFeet: return ToCubicFeet(); default: throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null); } } #region [ Numeric Interface Implementations ] /// <summary> /// Compares this instance to a specified object and returns an indication of their relative values. /// </summary> /// <param name="value">An object to compare, or null.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> /// <exception cref="ArgumentException">value is not a <see cref="Double"/> or <see cref="Volume"/>.</exception> public int CompareTo(object value) { if (value == null) return 1; double num; if (value is double) num = (double)value; else if (value is Volume) num = (Volume)value; else throw new ArgumentException("Argument must be a Double or a Volume"); return m_value < num ? -1 : (m_value > num ? 1 : 0); } /// <summary> /// Compares this instance to a specified <see cref="Volume"/> and returns an indication of their /// relative values. /// </summary> /// <param name="value">A <see cref="Volume"/> to compare.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> public int CompareTo(Volume value) { return CompareTo((double)value); } /// <summary> /// Compares this instance to a specified <see cref="Double"/> and returns an indication of their /// relative values. /// </summary> /// <param name="value">A <see cref="Double"/> to compare.</param> /// <returns> /// A signed number indicating the relative values of this instance and value. Returns less than zero /// if this instance is less than value, zero if this instance is equal to value, or greater than zero /// if this instance is greater than value. /// </returns> public int CompareTo(double value) { return m_value < value ? -1 : (m_value > value ? 1 : 0); } /// <summary> /// Returns a value indicating whether this instance is equal to a specified object. /// </summary> /// <param name="obj">An object to compare, or null.</param> /// <returns> /// True if obj is an instance of <see cref="Double"/> or <see cref="Volume"/> and equals the value of this instance; /// otherwise, False. /// </returns> public override bool Equals(object obj) { if (obj is double) return Equals((double)obj); if (obj is Volume) return Equals((Volume)obj); return false; } /// <summary> /// Returns a value indicating whether this instance is equal to a specified <see cref="Volume"/> value. /// </summary> /// <param name="obj">A <see cref="Volume"/> value to compare to this instance.</param> /// <returns> /// True if obj has the same value as this instance; otherwise, False. /// </returns> public bool Equals(Volume obj) { return Equals((double)obj); } /// <summary> /// Returns a value indicating whether this instance is equal to a specified <see cref="Double"/> value. /// </summary> /// <param name="obj">A <see cref="Double"/> value to compare to this instance.</param> /// <returns> /// True if obj has the same value as this instance; otherwise, False. /// </returns> public bool Equals(double obj) { return m_value == obj; } /// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns> /// A 32-bit signed integer hash code. /// </returns> public override int GetHashCode() { return m_value.GetHashCode(); } /// <summary>