/// <summary> /// Returns true if Employee instances are equal /// </summary> /// <param name="other">Instance of Employee to be compared</param> /// <returns>Boolean</returns> public bool Equals(Employee other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id != null && Id.Equals(other.Id) ) && ( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( ContractTypeName == other.ContractTypeName || ContractTypeName != null && ContractTypeName.Equals(other.ContractTypeName) ) && ( RoleId == other.RoleId || RoleId != null && RoleId.Equals(other.RoleId) ) && ( RoleName == other.RoleName || RoleName != null && RoleName.Equals(other.RoleName) ) && ( RoleDescription == other.RoleDescription || RoleDescription != null && RoleDescription.Equals(other.RoleDescription) ) && ( HourlySalary == other.HourlySalary || HourlySalary != null && HourlySalary.Equals(other.HourlySalary) ) && ( MonthlySalary == other.MonthlySalary || MonthlySalary != null && MonthlySalary.Equals(other.MonthlySalary) )); }
public static Employee Create(int id, string name, ContractTypeName contractTypeName, Role role, decimal salary) { switch (contractTypeName) { case ContractTypeName.HourlySalaryEmployee: return(new HourlyEmployee(id, name, ContractTypeName.HourlySalaryEmployee.ToString(), role, salary)); case ContractTypeName.MonthlySalaryEmployee: return(new MonthlyEmployee(id, name, ContractTypeName.MonthlySalaryEmployee.ToString(), role, salary)); default: return(null); } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (ContractTypeName != null) { hashCode = hashCode * 59 + ContractTypeName.GetHashCode(); } if (RoleId != null) { hashCode = hashCode * 59 + RoleId.GetHashCode(); } if (RoleName != null) { hashCode = hashCode * 59 + RoleName.GetHashCode(); } if (RoleDescription != null) { hashCode = hashCode * 59 + RoleDescription.GetHashCode(); } if (HourlySalary != null) { hashCode = hashCode * 59 + HourlySalary.GetHashCode(); } if (MonthlySalary != null) { hashCode = hashCode * 59 + MonthlySalary.GetHashCode(); } return(hashCode); } }