8 Ağustos 2016 Pazartesi

implicit Çevrim

Elimizde iki sınıf olsun.
public class Employee
{
  public string Name { get; set; }
  public string Email { get; set; }
}

public class EmployeeViewItem
{
  public string Name { get; set; }
  public string Email { get; set; }
}
Şöyle yaparız.
public class Employee
{
  public static implicit operator EmployeeViewItem(Employee employee)
  {
    EmployeeViewItem viewItem = new EmployeeViewItem();
    viewItem.Name = employee.Name;
    viewItem.Email = employee.Email;
    return new EmployeeViewItem();
  }

  public static implicit operator Employee(EmployeeViewItem ev)
  {
    var e = new Employee();
    e.Name = ev.Name;
    e.Email = ev.Email;
    return e;
  }
}


Hiç yorum yok:

Yorum Gönder