Example #1
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="Address">An object to compare with.</param>
        public Int32 CompareTo(Address Address)
        {
            if ((Object)Address == null)
            {
                throw new ArgumentNullException(nameof(Address), "The given address must not be null!");
            }

            var c = Country.CompareTo(Address.Country);

            if (c != 0)
            {
                return(c);
            }

            c = PostalCode.CompareTo(Address.PostalCode);
            if (c != 0)
            {
                return(c);
            }

            c = City.FirstText().CompareTo(Address.City.FirstText());
            if (c != 0)
            {
                return(c);
            }

            return(Street.CompareTo(Address.Street));
        }
Example #2
0
        /// <summary>
        /// Implementacja interfejsu IComparable w celu
        /// prawidłowego poążdkowania elemetów w listach sortowania
        /// </summary>
        /// <param name="obj">obiekt z którym porównuje aktulany obiekt (this)</param>
        /// <returns>
        /// [ < 0] - bieżące wystąpienie poprzedza obiekt
        /// [   0] - bieżące wystąpienie występuje w tym samym pożądku sortowania
        /// [ > 0] - bieżące wystąpienie występuje po obiekcie określonym przez CompareTo
        /// </returns>
        public int CompareTo(object obj)
        {
            Contact otherContact = obj as Contact;

            // na początku kontakty są sortowane alfabetycznie po miejscowości
            if (otherContact.City != null)
            {
                return(City.CompareTo(otherContact.City));
            }

            if (otherContact.Street != null)
            {
                return(Street.CompareTo(otherContact.Street));
            }

            if (otherContact.PostOffice != null)
            {
                return(PostOffice.CompareTo(otherContact.PostOffice));
            }

            if (otherContact.Email != null)
            {
                return(Email.CompareTo(otherContact.Email));
            }

            if (otherContact.Phone != null)
            {
                return(Phone.CompareTo(otherContact.Phone));
            }

            return(HomeNumber.CompareTo(otherContact.HomeNumber));
        }
Example #3
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="Address">An object to compare with.</param>
        public Int32 CompareTo(Address Address)
        {
            if (Address is null)
            {
                throw new ArgumentNullException(nameof(Address), "The given address must not be null!");
            }

            var c = Country.CompareTo(Address.Country);

            if (c != 0)
            {
                return(c);
            }

            c = Region.CompareTo(Address.Region);
            if (c != 0)
            {
                return(c);
            }

            c = PostalCode.CompareTo(Address.PostalCode);
            if (c != 0)
            {
                return(c);
            }

            c = City.FirstText().CompareTo(Address.City.FirstText());
            if (c != 0)
            {
                return(c);
            }

            c = Street.CompareTo(Address.Street);
            if (c != 0)
            {
                return(c);
            }

            c = HouseNumber.CompareTo(Address.HouseNumber);
            if (c != 0)
            {
                return(c);
            }

            c = FloorLevel.CompareTo(Address.FloorLevel);
            if (c != 0)
            {
                return(c);
            }

            return(Timezone.CompareTo(Address.Timezone));
        }
Example #4
0
        public int CompareTo(Address other)
        {
            int r = City.CompareTo(other.City);

            if (r == 0)
            {
                r = Street.CompareTo(other.Street);
            }
            if (r == 0)
            {
                r = Number.CompareTo(other.Number);
            }
            return(r);
        }
Example #5
0
        private int CompareStreet(string street)
        {
            if (street == null && Street == null)
            {
                return(0);
            }

            if (street == null && Street != null)
            {
                return(1);
            }

            if (street != null && Street == null)
            {
                return(-1);
            }

            return(Street.CompareTo(street));
        }