/// <summary> /// Serialize XML /// </summary> /// <param name="emp"></param> /// <returns></returns> private static String SerializeXML(Company.Employee emp) { try { String XmlizedString = null; XmlSerializer xs = new XmlSerializer(typeof(Company.Employee)); //create an instance of the MemoryStream class since we intend to keep the XML string //in memory instead of saving it to a file. MemoryStream memoryStream = new MemoryStream(); //XmlTextWriter - fast, non-cached, forward-only way of generating streams or files //containing XML data XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); //Serialize emp in the xmlTextWriter xs.Serialize(xmlTextWriter, emp); //Get the BaseStream of the xmlTextWriter in the Memory Stream memoryStream = (MemoryStream)xmlTextWriter.BaseStream; //Convert to array XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray()); return(XmlizedString); } catch (Exception) { throw; } }
public void AddEmployee(Employee employee) { if (employee == null) { throw new ArgumentNullException("employee", "Employee cannot be null."); } if (this.employees.ContainsKey(employee.Id)) { throw new ArgumentException("This employee is already in the list."); } this.employees.Add(employee.Id, employee); }
public int CompareTo(Employee other) { if (this.Id == other.Id) { return 0; } if (this.Id < other.Id) { return -1; } return 1; }
public void AddEmployee(Employee emp) { this.employees.Add(emp); }
public string Hire(Employee employeeName) { currentEmployees.Add(employeeName); return ($"hired {employeeName.firstName} "); }