Esempio n. 1
0
    public int CompareTo(Employee rhs, Employee.EmployeeComparer.ComparisonType which)
    {
        switch (which)
        {
        case Employee.EmployeeComparer.ComparisonType.EmpID:
            return(this.empID.CompareTo(rhs.empID));

        case Employee.EmployeeComparer.ComparisonType.Yrs:
            return(this.yearsOfSvc.CompareTo(rhs.yearsOfSvc));
        }
        return(0);
    }
        /// <summary>
        /// CompareTo:
        /// Uses the generic counterpart to the CompareTo funciton in IComparable
        /// Evaluates two employee classes based on their properties
        /// NOTE: This is the custom version of the same CompareTo method however:
        ///     -This version uses a nested called EmployeeComparer which implements IComparer
        ///     -The internal class allows a custom comparison to be selected when sorting
        ///     -This makes sorting much cleaner
        /// </summary>
        /// <param name="other">The employee being valuated</param>
        /// <returns>-1 if the previous is greater, 0 if they match, 1 if the latter is greater</returns>
        public int CompareTo(Employee other, Employee.EmployeeComparer.ComparisonType whichOne)
        {
            switch (whichOne) //Compare the employee based on the selected property
            {
            case Employee.EmployeeComparer.ComparisonType.Name:
                return(this.Name.CompareTo(other.Name));

            case Employee.EmployeeComparer.ComparisonType.Number:
                return(this.Number.CompareTo(other.Number));

            case Employee.EmployeeComparer.ComparisonType.Rate:
                return(this.Rate.CompareTo(other.Rate));

            case Employee.EmployeeComparer.ComparisonType.Hours:
                return(this.Hours.CompareTo(other.Hours));

            case Employee.EmployeeComparer.ComparisonType.Gross:
                return(this.Gross.CompareTo(other.Gross));
            }
            return(0);
        }
        /// <summary>
        /// Special implementation to be called by custom comparer
        /// </summary>
        /// <param name="rhs"></param>
        /// <param name="Which"></param>
        /// <returns>compareTo result value(-1,0,1)</returns>
        public int CompareTo(Employee rhs, Employee.EmployeeComparer.ComparisonType Which)
        {
            switch (Which)
            {
            case Employee.EmployeeComparer.ComparisonType.Name:
                return(this.Name.CompareTo(rhs.Name));

            case Employee.EmployeeComparer.ComparisonType.Number:
                return(this.Number.CompareTo(rhs.Number));

            case Employee.EmployeeComparer.ComparisonType.Rate:
                return(this.Rate.CompareTo(rhs.Rate));

            case Employee.EmployeeComparer.ComparisonType.Hours:
                return(this.Hours.CompareTo(rhs.Hours));

            case Employee.EmployeeComparer.ComparisonType.Gross:
                return(this.Gross.CompareTo(rhs.Gross));
            }
            return(0);
        }