I have a lot of this type of logic in my code when using the SqlDataReader Is there a cleaner more generic way to handle this?
if (reader["VisitingAddressId"] != DBNull.Value)
{
visitingAddress = new Address()
{
AddressId = Convert.ToInt64(reader["VisitingAddressId"]),
Address1 = reader["VisitingAddress"].ToString(),
AddressType = AddressType.VisitingAddress,
PostalCode = reader["VisitingPostal"].ToString(),
PostalDistrict = reader["VisitingPostalDistrict"].ToString()
};
}
if (reader["PostalAddressId"] != DBNull.Value)
{
postalAddress = new Address()
{
AddressId = Convert.ToInt64(reader["PostalAddressId"]),
Address1 = reader["PostalAddress"].ToString(),
AddressType = AddressType.PostalAddress,
PostalCode = reader["PostalPostal"].ToString(),
PostalDistrict = reader["PostalPostalDistrict"].ToString()
};
}