private void PopulateList(XmlNodeList employeeType, XmlNodeList employeeId, XmlNodeList employeeNames, XmlNodeList employeeSalary) { for (var counter = 0; counter < employeeType.Count; counter++) { var xmlAttribureCollection = employeeType[counter].Attributes; Employee currentEmployee; if (xmlAttribureCollection != null && xmlAttribureCollection["type"].Value == "1") { currentEmployee = new FixedSalaryEmployee( int.Parse(employeeId[counter].InnerText), employeeNames[counter].InnerText, double.Parse(employeeSalary[counter].InnerText) ); } else { currentEmployee = new HourlySalaryEmployee( int.Parse(employeeId[counter].InnerText), employeeNames[counter].InnerText, double.Parse(employeeSalary[counter].InnerText) ); } Add(currentEmployee); } }
static void Main(string[] args) { Employee[] emps = new Employee[2]; emps[0] = new FixedSalaryEmployee("Usman", 30, 4000); emps[1] = new HourlySalaryEmployee("Imran", 26, 10, 40); foreach (var emp in emps) { Console.WriteLine(emp + "\n"); } Console.ReadKey(); }
//Populate employee`s list private void PopulateList(XmlNodeList employeeType, XmlNodeList employeeId, XmlNodeList employeeNames, XmlNodeList employeeSalary) { int counter = 0; foreach (XmlNode type in employeeType) { XmlAttributeCollection xmlAttributeCollection = type.Attributes; Employee currentEmployee; if (xmlAttributeCollection != null && xmlAttributeCollection["type"].Value == "1") { currentEmployee = new FixedSalaryEmployee(int.Parse(employeeId[counter].InnerText), employeeNames[counter].InnerText, double.Parse(employeeSalary[counter].InnerText)); } else { currentEmployee = new HourlySalaryEmployee(int.Parse(employeeId[counter].InnerText), employeeNames[counter].InnerText, double.Parse(employeeSalary[counter].InnerText)); } Add(currentEmployee); counter++; } }
static List <Employee> CreateMockEmployees() { var fs = new FixedSalaryEmployee { Id = 1, Name = "Mario Rossi", Salary = 1500.00M, }; var hp = new HourlyPaidEmpoyee { Id = 2, Name = "Luigi Neri", HourlyRate = 20, }; hp.AddWorkedHours(2019, 8, 31, 4); hp.AddWorkedHours(2019, 8, 30, 6); hp.AddWorkedHours(2019, 8, 29, 2); hp.AddWorkedHours(2019, 8, 14, 5); var cp = new CommissionPaidEmployee { Id = 3, Name = "Anna Gialli", Percentage = 2, }; cp.AddCommission(2019, 8, 31, 2000); cp.AddCommission(2019, 8, 31, 1500.50M); cp.AddCommission(2019, 8, 7, 3000); return(new List <Employee> { fs, hp, cp }); }