SharpArch.Domain.DomainModel.BaseObject.GetHashCode C# (CSharp) Method

GetHashCode() public method

Returns a hash code for this instance.
This is used to provide the hash code identifier of an object using the signature properties of the object; although it's necessary for NHibernate's use, this can also be useful for business logic purposes and has been included in this base class, accordingly. Since it is recommended that GetHashCode change infrequently, if at all, in an object's lifetime, it's important that properties are carefully selected which truly represent the signature of an object.
public GetHashCode ( ) : int
return int
        public override int GetHashCode()
        {
            unchecked
            {
                PropertyInfo[] signatureProperties = this.GetSignatureProperties();

                // If no properties were flagged as being part of the signature of the object,
                // then simply return the hashcode of the base object as the hashcode.
                if (signatureProperties.Length == 0)
                {
                    // ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode
                    return base.GetHashCode();
                }

                // It's possible for two objects to return the same hash code based on
                // identically valued properties, even if they're of two different types,
                // so we include the object's type in the hash calculation
                int hashCode = this.GetType().GetHashCode();

                for (var i = 0; i < signatureProperties.Length; i++)
                {
                    PropertyInfo property = signatureProperties[i];
                    object value = property.GetValue(this, null);
                    if (value != null)
                    {
                        hashCode = (hashCode * HashMultiplier) ^ value.GetHashCode();
                    }
                }

                return hashCode;
            }
        }