1
I have the following classes:
public class Pessoal
{
public int ID { get; set; }
public string CPF { get; set; }
public string PIS { get; set; }
public string NOME { get; set; }
...
...
...
}
public class Dominio : DominioBase
{
public Pessoal Pessoal { get; set; }
public Pessoal PessoalAlteracao { get; set; }
}
I would like to copy the attributes of PessoalAlteracao
with the values of Pessoal
, but only how much value of the PessoalAlteracao
is equal to null
.
I can do through a if
:
PessoalAlteracao.CPF = PessoalAlteracao.CPF == null ? Pessoal.CPF : PessoalAlteracao.CPF;
But I would like to use a simpler form, I would like to create a loop, by attributes and match testing values?
♦ It would not be a clone, as one class the original data and other data changed (corrected) by the user. Then be null need to be equal (clone), otherwise I need to hide what was informed by the user. Thank you for the clarification.
– Jothaz
@Jota is a conditional cloning, but it’s a cloning. I edited to show you more that it doesn’t work to automate this.
– Maniero
I have come across projects that abuse Pattern or complicate architecture in excess, and a simple approach would solve. The idea really was to create a simplified code, but I understood your point of view, that there is no such thing as a free lunch. And everything must be measured and weighed the pros and cons.
– Jothaz