29
29
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
30
30
//---------------------------------------------------------------------------
31
31
32
+ using System ;
33
+
32
34
namespace RabbitMQ . Client . Framing . Impl
33
35
{
34
36
/// <summary>Represents a version of the AMQP specification.</summary>
@@ -45,7 +47,7 @@ namespace RabbitMQ.Client.Framing.Impl
45
47
/// special-cases 8-0, rewriting it at construction time to be 0-8 instead.
46
48
/// </para>
47
49
/// </remarks>
48
- internal class AmqpVersion
50
+ internal readonly struct AmqpVersion : IEquatable < AmqpVersion >
49
51
{
50
52
/// <summary>
51
53
/// Construct an <see cref="AmqpVersion"/> from major and minor version numbers.
@@ -70,27 +72,36 @@ public AmqpVersion(int major, int minor)
70
72
/// <summary>
71
73
/// The AMQP specification major version number.
72
74
/// </summary>
73
- public int Major { get ; private set ; }
75
+ public int Major { get ; }
74
76
75
77
/// <summary>
76
78
/// The AMQP specification minor version number.
77
79
/// </summary>
78
- public int Minor { get ; private set ; }
80
+ public int Minor { get ; }
79
81
80
82
/// <summary>
81
83
/// Implement value-equality comparison.
82
84
/// </summary>
83
85
public override bool Equals ( object other )
84
86
{
85
- return ( other is AmqpVersion version ) && ( version . Major == Major ) && ( version . Minor == Minor ) ;
87
+ return other is AmqpVersion version && Equals ( version ) ;
86
88
}
87
89
90
+ public bool Equals ( AmqpVersion other ) => Major == other . Major && Minor == other . Minor ;
91
+
92
+ public static bool operator == ( AmqpVersion left , AmqpVersion right ) => left . Equals ( right ) ;
93
+
94
+ public static bool operator != ( AmqpVersion left , AmqpVersion right ) => ! left . Equals ( right ) ;
95
+
88
96
/// <summary>
89
97
/// Implement hashing as for value-equality.
90
98
/// </summary>
91
99
public override int GetHashCode ( )
92
100
{
93
- return 31 * Major . GetHashCode ( ) + Minor . GetHashCode ( ) ;
101
+ unchecked
102
+ {
103
+ return ( Major * 397 ) ^ Minor ;
104
+ }
94
105
}
95
106
96
107
/// <summary>
0 commit comments