• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using System;
11 
12 namespace Google.Protobuf
13 {
14     /// <summary>
15     /// Struct used to hold the keys for the fieldByNumber table in DescriptorPool and the keys for the
16     /// extensionByNumber table in ExtensionRegistry.
17     /// </summary>
18     internal struct ObjectIntPair<T> : IEquatable<ObjectIntPair<T>> where T : class
19     {
20         private readonly int number;
21         private readonly T obj;
22 
ObjectIntPairGoogle.Protobuf.ObjectIntPair23         internal ObjectIntPair(T obj, int number)
24         {
25             this.number = number;
26             this.obj = obj;
27         }
28 
EqualsGoogle.Protobuf.ObjectIntPair29         public bool Equals(ObjectIntPair<T> other)
30         {
31             return obj == other.obj
32                    && number == other.number;
33         }
34 
35         public override bool Equals(object obj) => obj is ObjectIntPair<T> pair && Equals(pair);
36 
GetHashCodeGoogle.Protobuf.ObjectIntPair37         public override int GetHashCode()
38         {
39             return obj.GetHashCode() * ((1 << 16) - 1) + number;
40         }
41     }
42 }
43