Timestamped<T>
Represents value with a timestamp on it.
The timestamp typically represents the time the value was received, using an IScheduler's clock to obtain the current time.
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace System.Reactive
{
[Serializable]
public struct Timestamped<T> : IEquatable<Timestamped<T>>
{
public T Value {
[IsReadOnly]
get;
}
public DateTimeOffset Timestamp {
[IsReadOnly]
get;
}
public Timestamped(T value, DateTimeOffset timestamp)
{
Timestamp = timestamp;
Value = value;
}
public bool Equals(Timestamped<T> other)
{
if (other.Timestamp.Equals(Timestamp))
return EqualityComparer<T>.Default.Equals(Value, other.Value);
return false;
}
public static bool operator ==(Timestamped<T> first, Timestamped<T> second)
{
return first.Equals(second);
}
public static bool operator !=(Timestamped<T> first, Timestamped<T> second)
{
return !first.Equals(second);
}
public override bool Equals(object obj)
{
if (!(obj is Timestamped<T>))
return false;
Timestamped<T> other = (Timestamped<T>)obj;
return Equals(other);
}
public override int GetHashCode()
{
int hashCode = Timestamp.GetHashCode();
T value = Value;
return hashCode ^ (value?.GetHashCode() ?? 1979);
}
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "{0}@{1}", Value, Timestamp);
}
}
}