Got the following piece of code:
If boolFlag Then
With offer.Person1
entity.Birthdate = .BirthDate
entity.FirstName = .FirstGivenName
entity.LastName = .FamilyName
entity.Street = .StreetName
entity.HousNr = .HouseNumberIdentifier
entity.BoxNr = .BoxNumberIdentifier
entity.PostalCode = .PostalCode
entity.Municipality = .CityName
End With
Else
With offer.Person2
entity.Birthdate = .BirthDate
entity.FirstName = .FirstGivenName
entity.LastName = .FamilyName
entity.Street = .StreetName
entity.HousNr = .HouseNumberIdentifier
entity.BoxNr = .BoxNumberIdentifier
entity.PostalCode = .PostalCode
entity.Municipality = .CityName
End With
End If
Objects Person1 and Person2 are of different types, and those types do not share a common Interface / class. (And that can't be changed)
How do I avoid the duplicate code inside the With-blocks?