I came accross the following code today and I didn't like it. It's fairly obvious what it's doing but I'll add a little explanation here anyway:
Basically it reads all the settings for an app from the DB and the iterates through all of them looking for the DB Version and the APP Version then sets some variables to the values in the DB (to be used later).
I looked at it and thought it was a bit ugly - I don't like switch statements and I hate things that carry on iterating through a list once they're finished. So I decided to refactor it.
My question to all of you is how would you refactor it? Or do you think it even needs refactoring at all?
Here's the code:
using (var sqlConnection = new SqlConnection(Lfepa.Itrs.Framework.Configuration.ConnectionString))
{
sqlConnection.Open();
var dataTable = new DataTable("Settings");
var selectCommand = new SqlCommand(Lfepa.Itrs.Data.Database.Commands.dbo.SettingsSelAll, sqlConnection);
var reader = selectCommand.ExecuteReader();
while (reader.Read())
{
switch (reader[SettingKeyColumnName].ToString().ToUpper())
{
case DatabaseVersionKey:
DatabaseVersion = new Version(reader[SettingValueColumneName].ToString());
break;
case ApplicationVersionKey:
ApplicationVersion = new Version(reader[SettingValueColumneName].ToString());
break;
default:
break;
}
}
if (DatabaseVersion == null)
throw new ApplicationException("Colud not load Database Version Setting from the database.");
if (ApplicationVersion == null)
throw new ApplicationException("Colud not load Application Version Setting from the database.");
}
An air conditioner provides cold air inside your home or enclosed space by actually removing heat and humidity from the indoor air. It returns the cooled air to the indoor space, and transfers the unwanted heat and humidity outside.
LG, Samsung, Blue Star, Voltas, Hitachi, Daikin, and Panasonic, are some of the best brands in the top 10 AC brands in India. A. Yes. Features like easy filters, an auto cleaning system, a 100 percent copper condenser, and more make Samsung AC one of the most reliable and durable AC brands.
This mechanical system is an integral part of heating and cooling any modern building. AC is short for air conditioning. The terms HVAC and AC are often used interchangeably. CALL 1-800-365-1920 to speak with an HVAC professional today.
My two cents...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With