Class Duration
- Namespace
- Ranorex
- Assembly
- Ranorex.Core.dll
Represents a span of time.
[TypeConverter(typeof(Duration.DurationConverter))]
public sealed class Duration : IFormattable, IComparable<Duration>, IComparable, IEquatable<Duration>
- Inheritance
-
Duration
- Implements
- Inherited Members
Remarks
This class facilitates creating objects that represent a span of time by providing initializers that take an int (regarded as milliseconds) or a TimeSpan.
Constructors
Duration()
Constructs a new instance and initializes it with the value of Zero.
public Duration()
Duration(int)
Constructs a new instance and initializes it with the given number of milliseconds.
public Duration(int milliseconds)
Parameters
millisecondsintThe number of milliseconds to assign.
Duration(TimeSpan)
Constructs a new instance and initializes it with the value of the given TimeSpan.
public Duration(TimeSpan timeSpan)
Parameters
Fields
MaxValue
Represents the maximum Duration value. This field is read-only.
public static readonly Duration MaxValue
Field Value
MinValue
Represents the minimum Duration value. This field is read-only.
public static readonly Duration MinValue
Field Value
Zero
Represents the zero Duration value. This field is read-only.
public static readonly Duration Zero
Field Value
Properties
Milliseconds
Gets the number of milliseconds this instance represents.
public int Milliseconds { get; }
Property Value
TimeSpan
Gets a TimeSpan representation of this instance.
public TimeSpan TimeSpan { get; }
Property Value
Methods
Compare(Duration, Duration)
Compares two Duration objects and returns an indication of their relative values.
public static int Compare(Duration d1, Duration d2)
Parameters
Returns
- int
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero d1is less thand2.Zero d1is equal tod2.Greater than zero d1is greater thand2.
CompareTo(Duration)
Compares the current duration with another duration object.
public int CompareTo(Duration other)
Parameters
otherDurationA duration to compare with this instance.
Returns
- int
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
Value Meaning Less than zero This instance is less than other.Zero This instance is equal to other.Greater than zero This instance is greater than other.
CompareTo(object)
Compares the current duration with another object of the same type.
public int CompareTo(object obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance is less than obj.Zero This instance is equal to obj.Greater than zero This instance is greater than obj.
Exceptions
- ArgumentException
obj is not of type Duration.
Copy(Duration)
Returns a copy of the specified duration.
public static Duration Copy(Duration d)
Parameters
dDurationA duration.
Returns
- Duration
A copy of duration
d.
Equals(Duration)
public bool Equals(Duration other)
Parameters
Returns
- bool
trueif the current instance is equal to theotherparameter; otherwise,false.
Equals(object)
Returns true if the two objects are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
FromMilliseconds(int)
Returns a new Duration instance initialized by the milliseconds value.
public static Duration FromMilliseconds(int milliseconds)
Parameters
millisecondsintThe number of milliseconds.
Returns
FromTimeSpan(TimeSpan)
public static Duration FromTimeSpan(TimeSpan timeSpan)
Parameters
Returns
GetHashCode()
Gets a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code.
Parse(string)
public static Duration Parse(string durationString)
Parameters
durationStringstringA string representing a duration.
Returns
Exceptions
- ArgumentNullException
If
durationStringisnull.- FormatException
If
durationStringhas an invalid format.
ToMilliseconds(Duration)
Returns the number of milliseconds represented by the Duration instance.
public static int ToMilliseconds(Duration duration)
Parameters
Returns
- int
Milliseconds.
ToString()
Returns a string representation of this instance.
public override string ToString()
Returns
- string
A string representation of this instance.
Remarks
Calling this method is equivalent to calling ToString(string, IFormatProvider)
with parameters (null, InvariantCulture).
ToString(string)
Returns a string representation of this instance.
public string ToString(string format)
Parameters
Returns
- string
A string representation of this instance.
Remarks
The following string values are valid for format:
| Format String | Description and Associated Properties |
|---|---|
| g | General format. Replaces the format string by ms, s, m, or t as appropriate regarding the value of this instance. |
| ms | Millisecond format. |
| s | Second format. |
| h | Hour format. |
| d | Day format. |
| t | Full format, equal to the format returned by ToString(). |
ToString(string, IFormatProvider)
Returns a string representation of this instance.
public string ToString(string format, IFormatProvider formatProvider)
Parameters
formatstringThe string specifying the format to use or
nullto use the default format.formatProviderIFormatProviderThe IFormatProvider to use or
nullto obtain the format information from the current locale setting of the operating system.
Returns
- string
A string representation of this instance.
Remarks
The following string values are valid for format:
| Format String | Description and Associated Properties |
|---|---|
| g | General format. Replaces the format string by ms, s, m, or t as appropriate regarding the value of this instance. |
| ms | Millisecond format. |
| s | Second format. |
| h | Hour format. |
| d | Day format. |
| t | Full format, equal to the format returned by ToString(). |
ToTimeSpan(Duration)
public static TimeSpan ToTimeSpan(Duration duration)
Parameters
Returns
TryParse(string, out Duration)
public static bool TryParse(string durationString, out Duration duration)
Parameters
durationStringstringA string representing a duration.
durationDurationWhen this method returns, contains a Duration instance if parsing succeeded,
nullotherwise.
Returns
- bool
Trueif parsing succeeded, otherwisefalse.
Operators
operator +(Duration, Duration)
Adds two values.
public static Duration operator +(Duration left, Duration right)
Parameters
Returns
- Duration
The result of adding
leftandright.
operator +(Duration, int)
Adds two values.
public static Duration operator +(Duration left, int right)
Parameters
Returns
- Duration
The result of adding
leftandright.
operator +(Duration, TimeSpan)
Adds two values.
public static Duration operator +(Duration left, TimeSpan right)
Parameters
Returns
- Duration
The result of adding
leftandright.
operator +(int, Duration)
Adds two values.
public static Duration operator +(int left, Duration right)
Parameters
Returns
- Duration
The result of adding
leftandright.
operator +(TimeSpan, Duration)
Adds two values.
public static Duration operator +(TimeSpan left, Duration right)
Parameters
Returns
- Duration
The result of adding
leftandright.
operator ==(Duration, Duration)
Returns true if the two Duration instances are equal.
public static bool operator ==(Duration d1, Duration d2)
Parameters
Returns
operator >(Duration, Duration)
Returns whether left is greater than right.
public static bool operator >(Duration left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater thanright; otherwisefalse.
operator >(Duration, int)
Returns whether left is greater than right.
public static bool operator >(Duration left, int right)
Parameters
Returns
- bool
Trueifleftis greater thanright; otherwisefalse.
operator >(Duration, TimeSpan)
Returns whether left is greater than right.
public static bool operator >(Duration left, TimeSpan right)
Parameters
Returns
- bool
Trueifleftis greater thanright; otherwisefalse.
operator >(int, Duration)
Returns whether left is greater than right.
public static bool operator >(int left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater thanright; otherwisefalse.
operator >(TimeSpan, Duration)
Returns whether left is greater than right.
public static bool operator >(TimeSpan left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater thanright; otherwisefalse.
operator >=(Duration, Duration)
Returns whether left is greater than or equal to right.
public static bool operator >=(Duration left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater than or equal toright; otherwisefalse.
operator >=(Duration, int)
Returns whether left is greater than or equal to right.
public static bool operator >=(Duration left, int right)
Parameters
Returns
- bool
Trueifleftis greater than or equal toright; otherwisefalse.
operator >=(Duration, TimeSpan)
Returns whether left is greater than or equal to right.
public static bool operator >=(Duration left, TimeSpan right)
Parameters
Returns
- bool
Trueifleftis greater than or equal toright; otherwisefalse.
operator >=(int, Duration)
Returns whether left is greater than or equal to right.
public static bool operator >=(int left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater than or equal toright; otherwisefalse.
operator >=(TimeSpan, Duration)
Returns whether left is greater than or equal to right.
public static bool operator >=(TimeSpan left, Duration right)
Parameters
Returns
- bool
Trueifleftis greater than or equal toright; otherwisefalse.
implicit operator int(Duration)
Returns the number of milliseconds represented by the Duration instance.
public static implicit operator int(Duration duration)
Parameters
Returns
- int
Milliseconds.
implicit operator TimeSpan(Duration)
public static implicit operator TimeSpan(Duration duration)
Parameters
Returns
implicit operator Duration(int)
Returns a new Duration instance initialized by the milliseconds value.
public static implicit operator Duration(int milliseconds)
Parameters
millisecondsintThe number of milliseconds.
Returns
implicit operator Duration(TimeSpan)
public static implicit operator Duration(TimeSpan timeSpan)
Parameters
Returns
operator !=(Duration, Duration)
Returns true if the two Duration instances are not equal.
public static bool operator !=(Duration d1, Duration d2)
Parameters
Returns
operator <(Duration, Duration)
Returns whether left is less than right.
public static bool operator <(Duration left, Duration right)
Parameters
Returns
- bool
Trueifleftis less thanright; otherwisefalse.
operator <(Duration, int)
Returns whether left is less than right.
public static bool operator <(Duration left, int right)
Parameters
Returns
- bool
Trueifleftis less thanright; otherwisefalse.
operator <(Duration, TimeSpan)
Returns whether left is less than right.
public static bool operator <(Duration left, TimeSpan right)
Parameters
Returns
- bool
Trueifleftis less thanright; otherwisefalse.
operator <(int, Duration)
Returns whether left is less than right.
public static bool operator <(int left, Duration right)
Parameters
Returns
- bool
Trueifleftis less thanright; otherwisefalse.
operator <(TimeSpan, Duration)
Returns whether left is less than right.
public static bool operator <(TimeSpan left, Duration right)
Parameters
Returns
- bool
Trueifleftis less thanright; otherwisefalse.
operator <=(Duration, Duration)
Returns whether left is less than or equal to right.
public static bool operator <=(Duration left, Duration right)
Parameters
Returns
- bool
Trueifleftis less than or equal toright; otherwisefalse.
operator <=(Duration, int)
Returns whether left is less than or equal to right.
public static bool operator <=(Duration left, int right)
Parameters
Returns
- bool
Trueifleftis less than or equal toright; otherwisefalse.
operator <=(Duration, TimeSpan)
Returns whether left is less than or equal to right.
public static bool operator <=(Duration left, TimeSpan right)
Parameters
Returns
- bool
Trueifleftis less than or equal toright; otherwisefalse.
operator <=(int, Duration)
Returns whether left is less than or equal to right.
public static bool operator <=(int left, Duration right)
Parameters
Returns
- bool
Trueifleftis less than or equal toright; otherwisefalse.
operator <=(TimeSpan, Duration)
Returns whether left is less than or equal to right.
public static bool operator <=(TimeSpan left, Duration right)
Parameters
Returns
- bool
Trueifleftis less than or equal toright; otherwisefalse.
operator *(Duration, double)
Multiplies a duration by the specified factor.
public static Duration operator *(Duration duration, double factor)
Parameters
Returns
- Duration
The duration multiplied by the specified factor.
operator -(Duration, Duration)
Subtracts two values.
public static Duration operator -(Duration left, Duration right)
Parameters
Returns
- Duration
The result of subtracting
rightfromleft.
operator -(Duration, int)
Subtracts two values.
public static Duration operator -(Duration left, int right)
Parameters
Returns
- Duration
The result of subtracting
rightfromleft.
operator -(Duration, TimeSpan)
Subtracts two values.
public static Duration operator -(Duration left, TimeSpan right)
Parameters
Returns
- Duration
The result of subtracting
rightfromleft.
operator -(int, Duration)
Subtracts two values.
public static Duration operator -(int left, Duration right)
Parameters
Returns
- Duration
The result of subtracting
rightfromleft.
operator -(TimeSpan, Duration)
Subtracts two values.
public static Duration operator -(TimeSpan left, Duration right)
Parameters
Returns
- Duration
The result of subtracting
rightfromleft.