Advertisement
GeneralGDA

Equality Routines.

Apr 12th, 2018
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using JetBrains.Annotations;
  2.  
  3. namespace Cadwise.DressCode.Amidala.Commons.System
  4. {
  5.     public static class EqualityRoutine
  6.     {
  7.         private const int MagicPrime = 397;
  8.  
  9.         public static int HashCombine(int hash, int value)
  10.         {
  11.             unchecked
  12.             {
  13.                 return (hash * MagicPrime) ^ value;
  14.             }
  15.         }
  16.        
  17.         public static int HashCombine(int hash, [CanBeNull] object value)
  18.         {
  19.             unchecked
  20.             {
  21.                 return (hash * MagicPrime) ^ (value?.GetHashCode() ?? 0);
  22.             }
  23.         }
  24.  
  25.         public static bool TrivialEquality([NotNull] object self, [CanBeNull] object right, out bool result)
  26.         {
  27.             if (ReferenceEquals(null, right))
  28.             {
  29.                 result = false;
  30.                 return true;
  31.             }
  32.  
  33.             if (ReferenceEquals(self, right))
  34.             {
  35.                 result = true;
  36.                 return true;
  37.             }
  38.  
  39.             result = false;
  40.             return false;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement