// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; namespace Microsoft.Reactive.Testing { /// /// Record of a value including the virtual time it was produced on. /// /// Type of the value. #if !NO_DEBUGGER_ATTRIBUTES [DebuggerDisplay("{Value}@{Time}")] #endif #if !NO_SERIALIZABLE [Serializable] #endif public struct Recorded : IEquatable> { private readonly long _time; private readonly T _value; /// /// Gets the virtual time the value was produced on. /// public long Time { get { return _time; } } /// /// Gets the recorded value. /// public T Value { get { return _value; } } /// /// Creates a new object recording the production of the specified value at the given virtual time. /// /// Virtual time the value was produced on. /// Value that was produced. public Recorded(long time, T value) { _time = time; _value = value; } /// /// Checks whether the given recorded object is equal to the current instance. /// /// Recorded object to check for equality. /// true if both objects are equal; false otherwise. public bool Equals(Recorded other) { return Time == other.Time && EqualityComparer.Default.Equals(Value, other.Value); } /// /// Determines whether the two specified Recorded<T> values have the same Time and Value. /// /// The first Recorded<T> value to compare. /// The second Recorded<T> value to compare. /// true if the first Recorded<T> value has the same Time and Value as the second Recorded<T> value; otherwise, false. public static bool operator ==(Recorded left, Recorded right) { return left.Equals(right); } /// /// Determines whether the two specified Recorded<T> values don't have the same Time and Value. /// /// The first Recorded<T> value to compare. /// The second Recorded<T> value to compare. /// true if the first Recorded<T> value has a different Time or Value as the second Recorded<T> value; otherwise, false. public static bool operator !=(Recorded left, Recorded right) { return !left.Equals(right); } /// /// Determines whether the specified System.Object is equal to the current Recorded<T> value. /// /// The System.Object to compare with the current Recorded<T> value. /// true if the specified System.Object is equal to the current Recorded<T> value; otherwise, false. public override bool Equals(object obj) { if (obj is Recorded) return Equals((Recorded)obj); return false; } /// /// Returns the hash code for the current Recorded<T> value. /// /// A hash code for the current Recorded<T> value. public override int GetHashCode() { return Time.GetHashCode() + EqualityComparer.Default.GetHashCode(Value); } /// /// Returns a string representation of the current Recorded<T> value. /// /// String representation of the current Recorded<T> value. public override string ToString() { return Value.ToString() + "@" + Time.ToString(CultureInfo.CurrentCulture); } } }