コード例 #1
0
        public Dictionary <string, List <EmployeeComponent> > FindAllEmployees(Dictionary <string, List <EmployeeComponent> > employeesWithPositions = null)
        {
            if (employeesWithPositions == null)
            {
                employeesWithPositions = new Dictionary <string, List <EmployeeComponent> >();
            }
            if (!employeesWithPositions.ContainsKey(Position))
            {
                List <EmployeeComponent> employees = new List <EmployeeComponent> {
                    this
                };
                employeesWithPositions.Add(Position, employees);
            }
            else
            {
                employeesWithPositions[Position].Add(this);
            }
            IEnumerator iterator = CreateIterator();
            bool        hasNext  = iterator.MoveNext();

            while (hasNext)
            {
                EmployeeComponent employee = (EmployeeComponent)iterator.Current;
                employeesWithPositions = employee.FindAllEmployees(employeesWithPositions);
                hasNext = iterator.MoveNext();
            }

            return(employeesWithPositions);
        }
コード例 #2
0
ファイル: Company.cs プロジェクト: SMTRPZ/Novak-IT71
        public void PrintBackwards()
        {
            Dictionary <string, List <EmployeeComponent> > employees = new Dictionary <string, List <EmployeeComponent> >();

            _output.Print($"There are hierarchy of company by positions:");
            foreach (KeyValuePair <string, List <EmployeeComponent> > keyValue in _root.FindAllEmployees())
            {
                foreach (EmployeeComponent employee in keyValue.Value)
                {
                    _output.Print($"{employee}");
                }
            }
        }