Esempio n. 1
0
        /// <summary>
        ///     Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        ///     A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes
        ///     <paramref
        ///         name="obj" />
        ///     in the sort order. Zero This instance occurs in the same position in the sort order as
        ///     <paramref
        ///         name="obj" />
        ///     . Greater than zero This instance follows <paramref name="obj" /> in the sort order.
        /// </returns>
        /// <exception cref="System.ArgumentException"></exception>
        public int CompareTo(object obj)
        {
            IWeekDay bd = null;

            if (obj is string)
            {
                bd = new WeekDay(obj.ToString( ));
            }
            else
            {
                var weekDay = obj as IWeekDay;

                if (weekDay != null)
                {
                    bd = weekDay;
                }
            }

            if (bd == null)
            {
                throw new ArgumentException( );
            }

            int compare = DayOfWeek.CompareTo(bd.DayOfWeek);

            if (compare == 0)
            {
                compare = Offset.CompareTo(bd.Offset);
            }
            return(compare);
        }
Esempio n. 2
0
        /// <summary>
        ///     Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">
        ///     The <see cref="System.Object" /> to compare with this instance.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            var weekDay = obj as WeekDay;

            if (weekDay != null)
            {
                WeekDay ds = weekDay;
                return(ds.Offset == Offset &&
                       ds.DayOfWeek == DayOfWeek);
            }

// ReSharper disable BaseObjectEqualsIsObjectEquals
            return(base.Equals(obj));
// ReSharper restore BaseObjectEqualsIsObjectEquals
        }