diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs index 71628d50642..0edaffb9f49 100644 --- a/src/csharp/Grpc.Core/Internal/Timespec.cs +++ b/src/csharp/Grpc.Core/Internal/Timespec.cs @@ -25,8 +25,49 @@ namespace Grpc.Core.Internal /// gpr_timespec from grpc/support/time.h /// [StructLayout(LayoutKind.Sequential)] - internal struct Timespec + internal struct Timespec : IEquatable { + /// + /// Indicates whether this instance and a specified object are equal. + /// + public override bool Equals(object obj) + { + return obj is Timespec && Equals((Timespec)obj); + } + + /// + /// Returns the hash code for this instance. + /// + public override int GetHashCode() + { + unchecked + { + const int Prime = 373587911; + int i = (int)clock_type; + i = (i * Prime) ^ tv_nsec; + i = (i * Prime) ^ tv_nsec.GetHashCode(); + return i; + } + } + + /// + /// Returns the full type name of this instance. + /// + public override string ToString() + { + return typeof(Timespec).FullName; + } + + /// + /// Indicates whether this instance and a specified object are equal. + /// + public bool Equals(Timespec other) + { + return this.clock_type == other.clock_type + && this.tv_nsec == other.tv_nsec + && this.tv_sec == other.tv_sec; + } + const long NanosPerSecond = 1000 * 1000 * 1000; const long NanosPerTick = 100; const long TicksPerSecond = NanosPerSecond / NanosPerTick;