File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed
RabbitMQ.Client/client/api Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -156,9 +156,9 @@ public override bool Equals(object obj)
156156
157157 public bool Equals ( AmqpString other )
158158 {
159- if ( _value == null )
159+ if ( _value is null || other . _value is null )
160160 {
161- return _stringBytes . Equals ( other . _stringBytes ) ;
161+ return GetHashCode ( ) . Equals ( other . GetHashCode ( ) ) ;
162162 }
163163 else
164164 {
@@ -168,19 +168,12 @@ public bool Equals(AmqpString other)
168168
169169 public override int GetHashCode ( )
170170 {
171- if ( _value == null )
172- {
173- return ReadOnlyMemoryOfByteEqualityComparer . CalculateHashCode ( _stringBytes ) ;
174- }
175- else
176- {
177- return _value . GetHashCode ( ) ;
178- }
171+ return ReadOnlyMemoryOfByteEqualityComparer . CalculateHashCode ( _stringBytes ) ;
179172 }
180173
181174 public int CompareTo ( AmqpString other )
182175 {
183- if ( _value == null )
176+ if ( _value is null || other . _value is null )
184177 {
185178 return GetHashCode ( ) . CompareTo ( other . GetHashCode ( ) ) ;
186179 }
Original file line number Diff line number Diff line change 3636namespace RabbitMQ . Client
3737{
3838 /// <summary>
39- /// Convenience struct providing compile-time names for standard exchange types.
39+ /// Convenience class providing compile-time names for standard exchange types.
4040 /// </summary>
4141 /// <remarks>
4242 /// Use the static members of this class as values for the
Original file line number Diff line number Diff line change @@ -140,5 +140,19 @@ public void TestEqualityWhenUsingReadOnlyMemoryOfByte()
140140 var ex2 = new ExchangeName ( b2 ) ;
141141 Assert . Equal ( ex1 , ex2 ) ;
142142 }
143+
144+ [ Fact ]
145+ public void TestEqualityWhenUsingMixOfReadOnlyMemoryOfByteAndString ( )
146+ {
147+ ReadOnlyMemory < byte > b1 = new byte [ ] { ( byte ) 'f' , ( byte ) 'o' , ( byte ) 'o' } ;
148+ var ex1 = new ExchangeName ( b1 ) ;
149+
150+ string b2str = "foo" ;
151+ var ex2 = new ExchangeName ( b2str ) ;
152+
153+ Assert . Equal ( ex1 , ex2 ) ;
154+ Assert . Equal ( ex1 , b2str ) ;
155+ Assert . Equal ( ex2 , b2str ) ;
156+ }
143157 }
144158}
You can’t perform that action at this time.
0 commit comments