Thread: NullableTypes/src/Types NullableTimeSpan.cs,1.1,1.2
Status: Inactive
Brought to you by:
lukadotnet
From: Damien G. <dam...@us...> - 2005-10-11 09:25:29
|
Update of /cvsroot/nullabletypes/NullableTypes/src/Types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29226/src/Types Modified Files: NullableTimeSpan.cs Log Message: Clean up NullableTimeSpan and add new XML documentation. Index: NullableTimeSpan.cs =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Types/NullableTimeSpan.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableTimeSpan.cs 6 Oct 2005 16:05:35 -0000 1.1 --- NullableTimeSpan.cs 11 Oct 2005 09:25:33 -0000 1.2 *************** *** 5,9 **** // // Date Author Changes Reasons ! // 07-Apr-2003 DamienG Created New class // --- 5,10 ---- // // Date Author Changes Reasons ! // 29-Sep-2005 DamienG Created New class ! // 11-Oct-2005 DamienG Bugfix Clean up and all new XML documentation. // *************** *** 15,45 **** using sysXmlScm = System.Xml.Schema; [sys.Serializable] public struct NullableTimeSpan : INullable, sys.IComparable, sysXmlSrl.IXmlSerializable { #region Fields ! sys.TimeSpan _value; private bool _notNull; public static readonly NullableTimeSpan Null; /// <summary> ! /// A constant representing the largest possible value of a ! /// <see cref="NullableTimeSpan"/>. /// </summary> public static readonly NullableTimeSpan MaxValue = new NullableTimeSpan(sys.TimeSpan.MaxValue); /// <summary> ! /// A constant representing the smallest possible value of a ! /// <see cref="NullableTimeSpan"/>. /// </summary> public static readonly NullableTimeSpan MinValue = new NullableTimeSpan(sys.TimeSpan.MinValue); /// <summary> ! /// Represents a zero value that can be assigned to an instance of the ! /// <see cref="NullableTimeSpan"/> structure. /// </summary> - /// <remarks> - /// Zero field is a constant of the <see cref="NullableTimeSpan"/> structure. - /// </remarks> public static readonly NullableTimeSpan Zero = new NullableTimeSpan(0); --- 16,48 ---- using sysXmlScm = System.Xml.Schema; + /// <summary> + /// Represents an interval of time that is either a <see cref="System.TimeSpan" /> or <see cref="Null"/>. + /// </summary> [sys.Serializable] public struct NullableTimeSpan : INullable, sys.IComparable, sysXmlSrl.IXmlSerializable { + #region Fields ! ! private sys.TimeSpan _value; private bool _notNull; + /// <summary> + /// Represents the null <see cref="NullableTimeSpan"/>. This field is read-only. + /// </summary> public static readonly NullableTimeSpan Null; /// <summary> ! /// Represents the maximum <see cref="NullableTimeSpan"/> value. This field is read-only. /// </summary> public static readonly NullableTimeSpan MaxValue = new NullableTimeSpan(sys.TimeSpan.MaxValue); /// <summary> ! /// Represents the minimum <see cref="NullableTimeSpan"/> value. This field is read-only. /// </summary> public static readonly NullableTimeSpan MinValue = new NullableTimeSpan(sys.TimeSpan.MinValue); /// <summary> ! /// Represents the zero <see cref="NullableTimeSpan"/> value. This field is read-only. /// </summary> public static readonly NullableTimeSpan Zero = new NullableTimeSpan(0); *************** *** 47,60 **** #region Constructors ! public NullableTimeSpan (sys.TimeSpan timeSpan) { _value = timeSpan; _notNull = true; } ! public NullableTimeSpan (long ticks) { _value = new sys.TimeSpan (ticks); _notNull = true; } public NullableTimeSpan(int hours, int minutes, int seconds) { _value = new sys.TimeSpan(hours, minutes, seconds); --- 50,81 ---- #region Constructors ! ! /// <summary> ! /// Initializes a new <see cref="NullableTimeSpan"/> to the specified <see cref="System.TimeSpan"/> . ! /// </summary> ! /// <param name="timeSpan">A <see cref="System.TimeSpan"/>.</param> ! public NullableTimeSpan(sys.TimeSpan timeSpan) { _value = timeSpan; _notNull = true; } ! /// <summary> ! /// Initializes a new <see cref="NullableTimeSpan"/> to the specified number of ticks. ! /// </summary> ! /// <param name="ticks">A time period expressed in 100-nanosecond units.</param> ! public NullableTimeSpan(long ticks) { _value = new sys.TimeSpan (ticks); _notNull = true; } + /// <summary> + /// Initializes a new <see cref="NullableTimeSpan"/> to a specified number of hours, minutes, and seconds. + /// </summary> + /// <param name="hours">Number of hours.</param> + /// <param name="minutes">Number of minutes.</param> + /// <param name="seconds">Number of seconds.</param> + /// <exception cref="System.ArgumentOutOfRangeException"> + /// The parameters specify a <see cref="NullableTimeSpan"/> value less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>. + /// </exception> public NullableTimeSpan(int hours, int minutes, int seconds) { _value = new sys.TimeSpan(hours, minutes, seconds); *************** *** 62,101 **** } public NullableTimeSpan(int days, int hours, int minutes, int seconds) : this(days, hours, minutes, seconds, 0) { } public NullableTimeSpan(int days, int hours, int minutes, int seconds, int milliseconds) { _value = new sys.TimeSpan(days, hours, minutes, seconds, milliseconds); _notNull = true; } #endregion // Constructors #region INullable public bool IsNull { get { return !_notNull; } } #endregion // INullable #region IComparable - Ordering ! public int CompareTo(object value) { ! if (value == null) return 1; ! if (!(value is NullableTimeSpan)) throw new sys.ArgumentException(string.Format(sysGlb.CultureInfo.CurrentCulture, Locale.GetText("Value is not a {0}."), "NullableTypes.NullableTimeSpan")); ! NullableTimeSpan iValue = (NullableTimeSpan)value; ! if (iValue.IsNull && this.IsNull) ! return 0; ! ! if (iValue.IsNull) ! return 1; ! ! if (this.IsNull) ! return -1; ! return _value.CompareTo(iValue.Value); } --- 83,170 ---- } + /// <summary> + /// Initializes a new <see cref="NullableTimeSpan"/> to a specified number of days, hours, minutes, and seconds. + /// </summary> + /// <param name="days">Number of days.</param> + /// <param name="hours">Number of hours.</param> + /// <param name="minutes">Number of minutes.</param> + /// <param name="seconds">Number of seconds.</param> + /// <exception cref="System.ArgumentOutOfRangeException"> + /// The parameters specify a <see cref="NullableTimeSpan"/> value less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>. + /// </exception> public NullableTimeSpan(int days, int hours, int minutes, int seconds) : this(days, hours, minutes, seconds, 0) { } + /// <summary> + /// Initializes a new <see cref="NullableTimeSpan"/> to a specified number of days, hours, minutes, seconds and milliseconds. + /// </summary> + /// <param name="days">Number of days.</param> + /// <param name="hours">Number of hours.</param> + /// <param name="minutes">Number of minutes.</param> + /// <param name="seconds">Number of seconds.</param> + /// <param name="milliseconds">Number of milliseconds.</param> + /// <exception cref="System.ArgumentOutOfRangeException"> + /// The parameters specify a <see cref="NullableTimeSpan"/> value less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>. + /// </exception> public NullableTimeSpan(int days, int hours, int minutes, int seconds, int milliseconds) { _value = new sys.TimeSpan(days, hours, minutes, seconds, milliseconds); _notNull = true; } + #endregion // Constructors #region INullable + /// <summary> + /// Indicates whether or not this instance is <see cref="Null"/>. + /// </summary> + /// <value>true if this <see cref="NullableTimeSpan"/> is <see cref="Null"/>, otherwise false.</value> public bool IsNull { get { return !_notNull; } } + #endregion // INullable #region IComparable - Ordering ! ! /// <summary> ! /// Compares this instance to a specified object and returns an indication of their relative values. ! /// </summary> ! /// <param name="o">An object to compare, or <see langword="null" />.</param> ! /// <returns> ! /// <list type="table"> ! /// <listheader> ! /// <term>Value</term> ! /// <description>Condition</description> ! /// </listheader> ! /// <item> ! /// <term>-1</term> ! /// <description>This instance is less than <paramref name="o"/> or this instance is <see cref="Null"/> while <paramref name="o"/> is not.</description> ! /// </item> ! /// <item> ! /// <term>0</term> ! /// <description>This instance is equal to <paramref name="o"/>.</description> ! /// </item> ! /// <item> ! /// <term>1</term> ! /// <description>This instance is greater than <paramref name="o"/> or <paramref name="o"/> is <see cref="Null"/> while this instance is not.</description> ! /// </item> ! /// </list> ! /// </returns> ! /// <exception cref="System.ArgumentException"><paramref name="o" /> is not a <see cref="NullableTimeSpan"/>.</exception> ! public int CompareTo(object o) { ! if (o == null) return 1; ! if (!(o is NullableTimeSpan)) throw new sys.ArgumentException(string.Format(sysGlb.CultureInfo.CurrentCulture, Locale.GetText("Value is not a {0}."), "NullableTypes.NullableTimeSpan")); ! NullableTimeSpan ts = (NullableTimeSpan) o; ! if (ts.IsNull && IsNull) return 0; ! if (ts.IsNull) return 1; ! if (IsNull) return -1; ! return _value.CompareTo(ts.Value); } *************** *** 103,143 **** #region Equivalence - public override bool Equals(object value) { - if (!(value is NullableTimeSpan)) - return false; - else if (this.IsNull && ((NullableTimeSpan)value).IsNull) - return true; - else if (this.IsNull) - return false; - else if (((NullableTimeSpan)value).IsNull) - return false; - else - return (bool) (this == (NullableTimeSpan)value); - } ! public static NullableBoolean NotEquals(NullableTimeSpan x, NullableTimeSpan y) { ! return (x != y); } ! public static NullableBoolean operator == (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) return NullableBoolean.Null; ! return new NullableBoolean (x.Value == y.Value); } ! public static NullableBoolean operator != (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) return NullableBoolean.Null; ! return new NullableBoolean (!(x.Value == y.Value)); } ! public static NullableBoolean Equals(NullableTimeSpan x, NullableTimeSpan y) { ! return (x == y); } - public override int GetHashCode() { - return _value.GetHashCode(); - } #endregion // Equivalence #region IXmlSerializable /// <summary> /// This member supports the .NET Framework infrastructure and is not intended to be used directly --- 172,231 ---- #region Equivalence ! /// <summary> ! /// Returns a value indicating whether this instance is equal to a specified object. ! /// </summary> ! /// <param name="o">The object to compare with this instance.</param> ! /// <returns>true if <paramref name="o"/> is a <see cref="NullableGuid"/> that represents the same Guid as this instance; otherwise, false.</returns> ! public override bool Equals(object o) { ! if (!(o is NullableTimeSpan)) return false; ! NullableTimeSpan ts = (NullableTimeSpan) o; ! if (IsNull && ts.IsNull) return true; ! if (IsNull || ts.IsNull) return false; ! return (bool) (this == ts); } ! /// <summary> ! /// Indicates whether two <see cref="NullableTimeSpan"/> instances are equal. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <see cref="NullableBoolean.Null"/> if either <paramref name="t1"/> or <paramref name="t2"/> are <see cref="Null"/>, ! /// <see cref="NullableBoolean.True"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are equal, ! /// <see cref="NullableBoolean.False"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are not equal. ! public static NullableBoolean operator == (NullableTimeSpan t1, NullableTimeSpan t2) { ! if (t1.IsNull || t2.IsNull) return NullableBoolean.Null; ! return new NullableBoolean (t1.Value == t2.Value); } ! /// <summary> ! /// Indicates whether two <see cref="NullableTimeSpan"/> instances are not equal. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <see cref="NullableBoolean.Null"/> if either <paramref name="t1"/> or <paramref name="t2"/> are <see cref="Null"/>, ! /// <see cref="NullableBoolean.True"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are not equal, ! /// <see cref="NullableBoolean.False"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are equal. ! public static NullableBoolean operator != (NullableTimeSpan t1, NullableTimeSpan t2) { ! if (t1.IsNull || t1.IsNull) return NullableBoolean.Null; ! return new NullableBoolean (!(t1.Value == t1.Value)); } ! /// <summary> ! /// Indicates whether two <see cref="NullableTimeSpan"/> instances are equal. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <see cref="NullableBoolean.Null"/> if either <paramref name="t1"/> or <paramref name="t2"/> are <see cref="Null"/>, ! /// <see cref="NullableBoolean.True"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are equal, ! /// <see cref="NullableBoolean.False"/> if the values of <paramref name="t1"/> and <paramref name="t2"/> are not equal. ! public static NullableBoolean Equals(NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1 == t2); } #endregion // Equivalence #region IXmlSerializable + /// <summary> /// This member supports the .NET Framework infrastructure and is not intended to be used directly *************** *** 157,162 **** sysXmlScm.XmlSchemaElement rootElement = new sysXmlScm.XmlSchemaElement(); rootElement.Name = "NullableTimeSpan"; ! rootElement.SchemaTypeName = ! new sysXml.XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); rootElement.IsNillable = true; --- 245,249 ---- sysXmlScm.XmlSchemaElement rootElement = new sysXmlScm.XmlSchemaElement(); rootElement.Name = "NullableTimeSpan"; ! rootElement.SchemaTypeName = new sysXml.XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); rootElement.IsNillable = true; *************** *** 193,197 **** string elementValue = reader.IsEmptyElement ? null : reader.ReadElementString(); - sys.Console.WriteLine(elementValue); if (nilValue == null || nilValue == "false" || nilValue == "0") { _value = sysXml.XmlConvert.ToTimeSpan(elementValue); --- 280,283 ---- *************** *** 201,210 **** _notNull = false; } #endregion // IXmlSerializable #region Properties public sys.TimeSpan Value { get { ! if (this.IsNull) throw new NullableNullValueException(); --- 287,301 ---- _notNull = false; } + #endregion // IXmlSerializable #region Properties + /// <summary> + /// Contains the <see cref="System.TimeSpan"/> this instance represents if it is not <see cref="Null"/>. + /// </summary> + /// <exception cref="NullableNullValueException">instance represents <see cref="Null"/>.</exception> public sys.TimeSpan Value { get { ! if (IsNull) throw new NullableNullValueException(); *************** *** 212,240 **** } } #endregion // Properties #region Methods ! public static NullableBoolean GreaterThan(NullableTimeSpan x, NullableTimeSpan y) { ! return (x > y); } ! public static NullableBoolean GreaterThanOrEqual(NullableTimeSpan x, NullableTimeSpan y) { ! return (x >= y); } ! public static NullableBoolean LessThan(NullableTimeSpan x, NullableTimeSpan y) { ! return (x < y); } ! public static NullableBoolean LessThanOrEqual(NullableTimeSpan x, NullableTimeSpan y) { ! return (x <= y); } public static NullableTimeSpan Parse(string s) { ! return sys.TimeSpan.Parse (s); } ! public static NullableTimeSpan Add(NullableTimeSpan x, NullableTimeSpan y) { ! return (x + y); } --- 303,408 ---- } } + #endregion // Properties #region Methods ! ! /// <summary> ! /// Adds the specified <see cref="NullableTimeSpan"/> to this instance. ! /// </summary> ! /// <param name="ts">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns>A <see cref="NullableTimeSpan"/> that represents the value of this instance plus the value of <paramref name="ts"/>.</returns> ! /// <exception cref="System.OverflowException">The resulting <see cref="NullableTimeSpan"/> is less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>.</exception> ! public NullableTimeSpan Add(NullableTimeSpan ts) { ! return (IsNull || ts.IsNull) ? NullableTimeSpan.Null : (_value + ts.Value); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is greater than another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is greater than <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is less than or equal to <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean GreaterThan(NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1 > t2); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is greater than or equal to another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is less than <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean GreaterThanOrEqual(NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1 >= t2); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is less than another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is less than <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean LessThan(NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1 < t2); } + /// <summary> + /// Indicates whether a specified <see cref="NullableTimeSpan"/> is less than another specified <see cref="NullableTimeSpan"/>. + /// </summary> + /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> + /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> + /// <returns> + /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is less than <paramref name="t2"/>, + /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, + /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>. + /// </returns> + public static NullableBoolean LessThanOrEqual(NullableTimeSpan t1, NullableTimeSpan t2) { + return (t1 <= t2); + } + + /// <summary> + /// Constructs a <see cref="NullableTimeSpan"/> from a time indicated by a specified string. + /// </summary> + /// <param name="s">A string.</param> + /// <returns>A <see cref="NullableTimeSpan"/> that corresponds to s.</returns> + /// <exception cref="System.ArgumentNullException">s is <see langword="null" />.</exception> + /// <exception cref="System.FormatException">s has an invalid format.</exception> + /// <exception cref="System.OverflowException"> + /// <paramref name="s"/> represents a number less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/> + /// or at least one of the hours, minutes, or seconds components is outside its valid range. + /// </exception> public static NullableTimeSpan Parse(string s) { ! return sys.TimeSpan.Parse(s); } ! /// <summary> ! /// Subtracts the specified <see cref="NullableTimeSpan"/> from this instance. ! /// </summary> ! /// <param name="ts">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns>A <see cref="NullableTimeSpan"/> whose value is the result of the value of this instance minus the value of <paramref name="ts"/>.</returns> ! /// <exception cref="System.OverflowException">The resulting <see cref="NullableTimeSpan"/> is less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>.</exception> ! public NullableTimeSpan Subtract(NullableTimeSpan ts) { ! return (IsNull || ts.IsNull) ? NullableTimeSpan.Null : (_value - ts.Value); ! } ! ! /// <summary> ! /// Returns a hash code for this instance. ! /// </summary> ! /// <returns>A 32-bit signed integer hash code.</returns> ! public override int GetHashCode() { ! return _value.GetHashCode(); } *************** *** 242,318 **** #region Operators - public static NullableTimeSpan operator + (NullableTimeSpan x, NullableTimeSpan y) { - if (x.IsNull || y.IsNull) - return NullableTimeSpan.Null; ! checked { ! return new NullableTimeSpan(x.Value + y.Value); ! } } ! public static NullableTimeSpan operator - (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) ! return NullableTimeSpan.Null; ! ! checked { ! return new NullableTimeSpan(x.Value - y.Value); ! } } ! public static NullableBoolean operator > (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) ! return NullableBoolean.Null; ! ! if (x.Value.CompareTo (y.Value) > 0) ! return new NullableBoolean (true); ! else ! return new NullableBoolean (false); } ! public static NullableBoolean operator >= (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) ! return NullableBoolean.Null; ! ! if (x.Value.CompareTo (y.Value) >= 0) ! return new NullableBoolean (true); ! else ! return new NullableBoolean (false); } ! public static NullableBoolean operator < (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) ! return NullableBoolean.Null; ! ! if (x.Value.CompareTo (y.Value) < 0) ! return new NullableBoolean (true); ! else ! return new NullableBoolean (false); } ! public static NullableBoolean operator <= (NullableTimeSpan x, NullableTimeSpan y) { ! if (x.IsNull || y.IsNull) ! return NullableBoolean.Null; ! ! if (x.Value.CompareTo (y.Value) <= 0) ! return new NullableBoolean (true); ! else ! return new NullableBoolean (false); } #endregion // Operators #region Conversion Operators ! public static explicit operator sys.TimeSpan(NullableTimeSpan x) { ! return x.Value; } ! public static explicit operator NullableTimeSpan(NullableString x) { ! if (x.IsNull) ! return NullableTimeSpan.Null; ! else ! return NullableTimeSpan.Parse (x.Value); } ! public static implicit operator NullableTimeSpan(sys.TimeSpan x) { ! return new NullableTimeSpan (x); } --- 410,543 ---- #region Operators ! /// <summary> ! /// Adds two specified <see cref="NullableTimeSpan"/> instances. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A NullableTimeSpan.</param> ! /// <returns>A <see cref="NullableTimeSpan"/> whose value is the sum of the values of <paramref name="t1"/> and <paramref name="t2"/> or ! /// <see cref="NullableTimeSpan.Null"/> if either instance is <see cref="NullableTimeSpan.Null"/>. ! ///</returns> ! /// <exception cref="System.OverflowException">The resulting <see cref="NullableTimeSpan"/> is less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>.</exception> ! public static NullableTimeSpan operator + (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableTimeSpan.Null : new NullableTimeSpan(t1.Value + t2.Value); } ! /// <summary> ! /// Subtracts a specified <see cref="NullableTimeSpan"/> from another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns>A <see cref="NullableTimeSpan"/> whose value is the result of the value of <paramref name="t1"/> minus the value of <paramref name="t2"/> or ! /// <see cref="NullableTimeSpan.Null"/> if either instance is <see cref="NullableTimeSpan.Null"/>. ! ///</returns> ! /// <exception cref="System.OverflowException">The resulting <see cref="NullableTimeSpan"/> is less than <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>.</exception> ! public static NullableTimeSpan operator - (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableTimeSpan.Null : new NullableTimeSpan(t1.Value - t2.Value); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is greater than another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is greater than <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is less than or equal to <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean operator > (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableBoolean.Null : new NullableBoolean(t1.Value.CompareTo(t2.Value) > 0); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is greater than or equal to another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is less than <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean operator >= (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableBoolean.Null : new NullableBoolean(t1.Value.CompareTo (t2.Value) >= 0); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is less than another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is less than <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean operator < (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableBoolean.Null : new NullableBoolean(t1.Value.CompareTo(t2.Value) < 0); } ! /// <summary> ! /// Indicates whether a specified <see cref="NullableTimeSpan"/> is less than another specified <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="t1">A <see cref="NullableTimeSpan"/>.</param> ! /// <param name="t2">A <see cref="NullableTimeSpan"/>.</param> ! /// <returns> ! /// <see cref="NullableBoolean.True"/> if <paramref name="t1"/> is less than <paramref name="t2"/>, ! /// <see cref="NullableBoolean.Null"/> if one or both of the instances are NullableTimeSpan.Null, ! /// <see cref="NullableBoolean.False"/> if <paramref name="t1"/> is greater than or equal to <paramref name="t2"/>. ! /// </returns> ! public static NullableBoolean operator <= (NullableTimeSpan t1, NullableTimeSpan t2) { ! return (t1.IsNull || t2.IsNull) ? NullableBoolean.Null : new NullableBoolean(t1.Value.CompareTo(t2.Value) <= 0); } + #endregion // Operators #region Conversion Operators ! ! /// <summary> ! /// Converts the specified <see cref="NullableTimeSpan"/> to a <see cref="System.TimeSpan"/>. ! /// </summary> ! /// <param name="ts">A <see cref="NullableTimeSpan"/> to convert.</param> ! /// <returns> ! /// A <see cref="System.TimeSpan"/> set to the <see cref="Value"/> of the ! /// <see cref="NullableTimeSpan"/>. ! /// </returns> ! /// <exception cref="NullableNullValueException"><paramref name="ts"/> is <see cref="Null"/>.</exception> ! public static explicit operator sys.TimeSpan(NullableTimeSpan ts) { ! return ts.Value; } ! /// <summary> ! /// Converts the specified <see cref="NullableString"/> to a <see cref="NullableTimeSpan"/>. ! /// </summary> ! /// <param name="s">A <see cref="NullableString"/> to convert.</param> ! /// <returns> ! /// <see cref="Null"/> if <paramref name="x"/> is ! /// <see cref="NullableString.Null"/> otherwise a new ! /// <see cref="NullableTimeSpan"/> structure containing the parsed value. ! /// </returns> ! /// <exception cref="System.FormatException"> ! /// <paramref name="s"/>does not consist solely of an optional sign followed ! /// by a sequence of digits ranging from 0 to 9. ! /// </exception> ! /// <exception cref="System.OverflowException"><paramref name="s"/>represents a timespan less than ! /// <see cref="NullableTimeSpan.MinValue"/> or greater than <see cref="NullableTimeSpan.MaxValue"/>. ! /// </exception> ! public static explicit operator NullableTimeSpan(NullableString s) { ! return (s.IsNull) ? NullableTimeSpan.Null : NullableTimeSpan.Parse(s.Value); } ! /// <summary> ! /// Converts the <see cref="System.TimeSpan"/> parameter to a ! /// <see cref="NullableTimeSpan"/> structure. ! /// </summary> ! /// <param name="ts">A <see cref="System.TimeSpan"/> to convert.</param> ! /// <returns> ! /// A new <see cref="NullableTimeSpan"/> constructed from <paramref name="ts"/>. ! /// </returns> ! public static implicit operator NullableTimeSpan(sys.TimeSpan ts) { ! return new NullableTimeSpan(ts); } *************** *** 320,342 **** #region Conversions /// <summary> ! /// Converts to a NullableString representing the time span. /// </summary> ! /// <returns>A NullableString representative of the NullableTimeSpan.</returns> ! public NullableString ToNullableString () { return (NullableString) this; } /// <summary> ! /// Converts the NullableTimeSpan value to a string. /// </summary> ! /// <returns>A string representative of the NullableTimeSpan.</returns> ! public override string ToString () { ! if (this.IsNull) ! return Locale.GetText("Null"); ! else ! return _value.ToString (); } #endregion // Conversions } ! } --- 545,566 ---- #region Conversions + /// <summary> ! /// Returns the <see cref="NullableString"/> representation of this instance. /// </summary> ! /// <returns>A <see cref="NullableString"/> that represents this instance.</returns> ! public NullableString ToNullableString() { return (NullableString) this; } /// <summary> ! /// Returns the string representation of the value of this instance. /// </summary> ! /// <returns>A string that represents this instance.</returns> ! public override string ToString() { ! return (IsNull) ? Locale.GetText("Null") : _value.ToString(); } + #endregion // Conversions } ! } \ No newline at end of file |