mercredi 3 juillet 2019

How can I solve my problem with design patterns?

I'have to map a dynamic object to a DTO object. The dynamic object can have logically different properties in different contexts and I'd like to create an adapter class that turns my dynamic object into a particular object. Grazie a chiunque mi vorrà aumetare Thanks to anyone who wants to improve.

class DTO {
    public int Id {get; set;}
    public string CampoA { get; set;}
    public string CampoB { get; set;}
}

class DTO2 {
    public int Id {get; set;}
    public bool isExample { get; set;}
    public string name { get; set;}
}

class Main {

  public DTO parseDynamicObjectToDTO(Dynaimc dynamic){ 
     DTO d = new DTO();
     d.Id = dynamic.Prop.Id; 
     d.CampoA = dynamic.Prop.CPA;
     d.CampoB = dynamic.Prop.CPB;

      return d;
  }

  public DTO parseDynamicObjectToDTO2(Dynaimc dynamic){ 
     DTO2 d = new DTO2();
     d.Id = dynamic2.Prop.Id; 
     d.isExample = dynamic2.Prop.ISEX;
     d.name = dynamic2.Prop.NAME;

      return d;
  }

}

Aucun commentaire:

Enregistrer un commentaire