2
In a system integration there are data updates on both sides, where you get the record of Side A and the record of side B. If there are null fields in A and these exist in B then A is supplemented with B the inverse is also true, it is as if it were a merge between the records. To resolve this issue I tried two ways that worked, however, at least for me, is "gambiarrado".
1st Approach - Reflection
foreach (var propertyInfo in entidadeA.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
{
var valor = propertyInfo.GetValue(entidadeA, null);
camposNull.Add(nameof(propertyInfo.Name))
}
2nd Approach - Entity instantiation verification
public class EntidadeA{
private string _campoA {get; set;}
public string CampoA
{
get { return _campoA; }
set
{
_campoA = value;
if(string.IsNullOrEmpty(value))
camposNull.Add(nameof(CampoA))
}
}
The entities have more than 20 fields, so my goal is to reduce as much as possible if-else
. Is there any other way to do this? The second way, if the entity is used in a serialization for JSON or XML could generate problems?
Do you have several different entities? Each with 20+ fields?
– MurariAlex
No no, it’s just a few... if I’m not mistaken 2 or 3...
– JcSaint
Did the answer resolve what was in doubt? Something else needs to be improved?
– Maniero