I have a situation where I am loading a very unnormalized record set from Excel. I pull in each row and create the objects from it one at a time. each row could contain a company and / or a client.
My issue is that multiple rows could have the same objects, so I may have already created it. I do a comparison to see if it is already in the list. If so I need to merge the two objects to ensure I have not gained any new information from the second row.
so:
company - client - address - phone
----------------------------------------
mycompany - - myaddress -
mycompnay - myclient - - myphone
so the first row would create a company object with an address of “myaddress”.
The second row would create another company object (which by my rules is the same company as the name is the same), this also having a client reference and a phone number.
So I would know they are the same but need to ensure all the data is merged into one object.
At the moment I am creating a utility class that takes both objects, (one being the primary and the other to be merged, so one has priority if there is a clash), it goes through each variable and assigns the values if there are any. This is a bit boiler plate heavy and I was hoping there might be some utility I could utilize to do the manual work for me.
The example has been simplified as there are a fair few other variables, some basic types and others that are more complex items.
Reflection would work. Something like: