Example #1
0
    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);
    }
Example #2
0
        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();
        }
Example #3
0
    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);
    }
Example #4
0
        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);
            }
        }
Example #5
0
 public Employee(ThirdPartyEmployee e)
 {
     _baseEmployee = e;
 }
Example #6
0
 public Employee()
 {
     _baseEmployee = new ThirdPartyEmployee();
 }