123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
-
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- namespace UniRx
- {
-
-
-
-
-
- [Serializable]
- public struct Timestamped<T> : IEquatable<Timestamped<T>>
- {
- private readonly DateTimeOffset _timestamp;
- private readonly T _value;
-
-
-
-
-
- public Timestamped(T value, DateTimeOffset timestamp)
- {
- _timestamp = timestamp;
- _value = value;
- }
-
-
-
- public T Value
- {
- get { return _value; }
- }
-
-
-
- public DateTimeOffset Timestamp
- {
- get { return _timestamp; }
- }
-
-
-
-
-
- public bool Equals(Timestamped<T> other)
- {
- return other.Timestamp.Equals(Timestamp) && EqualityComparer<T>.Default.Equals(Value, other.Value);
- }
-
-
-
-
-
-
- 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;
- var other = (Timestamped<T>)obj;
- return this.Equals(other);
- }
-
-
-
-
- public override int GetHashCode()
- {
- var valueHashCode = Value == null ? 1979 : Value.GetHashCode();
- return _timestamp.GetHashCode() ^ valueHashCode;
- }
-
-
-
-
- public override string ToString()
- {
- return String.Format(CultureInfo.CurrentCulture, "{0}@{1}", Value, Timestamp);
- }
- }
-
-
-
- public static class Timestamped
- {
-
-
-
-
-
-
-
- public static Timestamped<T> Create<T>(T value, DateTimeOffset timestamp)
- {
- return new Timestamped<T>(value, timestamp);
- }
- }
- }
|