Пример #1
0
        /// <summary>
        /// Should ONLY contain the "business value signature" of the object and not the Id, 
        /// which is handled by <see cref="Entity" />.  This method should return a unique 
        /// int representing a unique signature of the domain object.  For 
        /// example, no two different orders should have the same ShipToName, OrderDate and OrderedBy;
        /// therefore, the returned "signature" should be expressed as demonstrated below.
        /// 
        /// Alternatively, we could decorate properties with the [DomainSignature] attribute, as shown in
        /// <see cref="Customer" />, but here's an example of overriding it nonetheless.
        /// </summary>
        public override bool HasSameObjectSignatureAs(BaseObject compareTo) {
            Order orderCompareTo = compareTo as Order;

            return orderCompareTo != null && ShipToName.Equals(orderCompareTo.ShipToName) &&
                (OrderDate ?? DateTime.MinValue).Equals((orderCompareTo.OrderDate ?? DateTime.MinValue)) &&
                OrderedBy.Equals(orderCompareTo.OrderedBy);
        }
Пример #2
0
        /// <summary>
        /// You may override this method to provide your own comparison routine.
        /// </summary>
        public virtual bool HasSameObjectSignatureAs(BaseObject compareTo) {
            IEnumerable<PropertyInfo> signatureProperties = GetSignatureProperties();

            foreach (PropertyInfo property in signatureProperties) {
                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; otherwise, if there were no signature 
            // properties, then simply return the default bahavior of Equals
            return signatureProperties.Any() || base.Equals(compareTo);
        }