Пример #1
0
        /// <summary>
        /// <para>
        /// Determines whether the specified object is equal to
        /// the current object.
        /// </para>
        /// <para>
        /// Two value objects are considered equal if they are the same type
        /// and have all properties equal.
        /// </para>
        /// </summary>
        /// <param name="other">The object to compare with the current object.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public virtual bool Equals(IValueObject other)
        {
            if (other == null)
            {
                return(false);
            }

            var t         = GetType();
            var otherType = other.GetType();

            if (t != otherType)
            {
                return(false);
            }

            var properties = GetProperties();

            foreach (var property in properties)
            {
                var value1 = property.GetValue(other);
                var value2 = property.GetValue(this);

                if (value1 == null)
                {
                    if (value2 != null)
                    {
                        return(false);
                    }
                }
                else if (!value1.Equals(value2))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
 public virtual bool Equals(IValueObject other)
 {
     return((other != null) &&
            (GetType() == other.GetType()) &&
            GetHashCode().Equals(other.GetHashCode()));
 }