public override bool Equals(SerializableImportDefinition other) { var otherType = other as PropertyBasedImportDefinition; if (ReferenceEquals(this, other)) { return(true); } // Check if other is a null reference by using ReferenceEquals because // we overload the == operator. If other isn't actually null then // we get an infinite loop where we're constantly trying to compare to null. return(!ReferenceEquals(otherType, null) && string.Equals(ContractName, otherType.ContractName, StringComparison.OrdinalIgnoreCase) && RequiredTypeIdentity.Equals(otherType.RequiredTypeIdentity) && Property == otherType.Property); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { // As obtained from the Jon Skeet answer to: // http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode // And adapted towards the Modified Bernstein (shown here: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx) // // Overflow is fine, just wrap unchecked { // Pick a random prime number int hash = 17; // Mash the hash together with yet another random prime number hash = (hash * 23) ^ ContractName.GetHashCode(); hash = (hash * 23) ^ RequiredTypeIdentity.GetHashCode(); hash = (hash * 23) ^ Property.GetHashCode(); return(hash); } }