コード例 #1
0
        public static BaseEmployee GetFromString(string line)
        {
            string[] splitedData = line.Split(';');

            if (splitedData.Length != 4)
            {
                throw new Exception("Строка имеет неверный формат");
            }

            BaseEmployee employee = default;

            string lineId     = splitedData[0].Substring(splitedData[0].IndexOf(":") + 1);
            string lineName   = splitedData[1].Substring(splitedData[1].IndexOf(":") + 1);
            string lineSalary = splitedData[2].Substring(splitedData[2].IndexOf(":") + 1);
            string lineType   = splitedData[3].Substring(splitedData[3].IndexOf(":") + 1);

            if (lineType == FixedEmployee.EMPLOYEE_TYPE_NAME)
            {
                employee = new FixedEmployee();
            }
            else
            {
                employee = new HourlyEmployee();
            }

            employee.Id     = int.Parse(lineId);
            employee.Name   = lineName;
            employee.Salary = double.Parse(lineSalary);

            return(employee);
        }
コード例 #2
0
        private static void ReadFromFile(string fileName)
        {
            employeeList.Clear();
            List <string> fileLines = ReadAllLines(fileName);

            foreach (string line in fileLines)
            {
                employeeList.Add(BaseEmployee.GetFromString(line));
            }
        }