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

HasSameObjectSignatureAs() public method

Determines whether the current object has the same object signature as the specified object.
You may override this method to provide your own comparison routine.
public HasSameObjectSignatureAs ( BaseObject compareTo ) : bool
compareTo BaseObject The object to compare to.
return bool
        public virtual bool HasSameObjectSignatureAs(BaseObject compareTo)
        {
            PropertyInfo[] signatureProperties = this.GetSignatureProperties();

            // if there were no signature properties, then simply return the default behavior of Equals
            if (signatureProperties.Length == 0)
            {
                // ReSharper disable once BaseObjectEqualsIsObjectEquals
                return base.Equals(compareTo);
            }

            // use for loop instead of foreach/LINQ for performance reasons.
            // ReSharper disable once ForCanBeConvertedToForeach
            // ReSharper disable once LoopCanBeConvertedToQuery
            for (var index = 0; index < signatureProperties.Length; index++)
            {
                PropertyInfo property = signatureProperties[index];
                object valueOfThisObject = property.GetValue(this, null);
                object valueToCompareTo = property.GetValue(compareTo, null);

                if (valueOfThisObject == null && valueToCompareTo == null)
                {
                    continue;
                }

                if ((valueOfThisObject == null ^ valueToCompareTo == null) ||
                    (!valueOfThisObject.Equals(valueToCompareTo)))
                {
                    return false;
                }
            }

            // If we've gotten this far and signature properties were found, then we can
            // assume that everything matched
            return true;
        }