public static Employee From(ThirdPartyEmployee employee) { var result = new Employee(); result.FirstName = thirdPartyEmployee.F_Name; result.LastName = thirdPartyEmployee.L_Name; result.MobileTelephone = thirdPartyEmployee.Telephone1; return(result); }
static void Main() { var thirdPartyEmployee = new ThirdPartyEmployee(); var employeeTarget = new EmployeeAdapter(thirdPartyEmployee); var client = new EmployeeClient(employeeTarget); var employees = client.GetEmployees(); client.RenderEmployees(employees); Console.ReadLine(); }
public static Employee ConvertTo(this ThirdPartyEmployee thirdPartyEmployee) { var result = new Employee(); if (map.Count() < typeof(Employee).GetProperties().Count()) { throw new Exception("Forget to add mapping for new field!"); } foreach (var prop in typeof(ThirdPartyEmployee).GetProperties()) { var temp = result.GetProperties().Where(x => x.Name == map[prop.Name]).First(); temp.SetValue(result, prop.GetValue(thirdPartyEmployee)); } return(result); }
public static void Adapter() { var classAdapter = new ClassEmployeeAdapter(); foreach (var item in classAdapter.GetEmployees()) { Console.WriteLine(item); } var adaptee = new ThirdPartyEmployee(); var objectAdapter = new ObjectEmployeeAdapter(adaptee); foreach (var item in objectAdapter.GetEmployees()) { Console.WriteLine(item); } }
public Employee(ThirdPartyEmployee e) { _baseEmployee = e; }
public Employee() { _baseEmployee = new ThirdPartyEmployee(); }