I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that
Settings.Default
provides. See here for more info .
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info .
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info .
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that
Settings.Default
provides. See here for more info .
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
- 44.6k
- 9
- 84
- 190
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = String.Format($"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ");";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = String.Format($"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ");
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.
I love that you're storing the interval in a config, but there's some issues with your implementation of that.
- This class doesn't need the whole config file.
There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.
GetConfigSection
isn't a very nice way to access the configuration.
It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default
provides. See here for more info.
Lastly, this block looks like a wonderful place to extract a method and use String.Format
string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", "; string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and "; string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : ""); string UptimeString = days + hours + mins;
For example:
string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));
Or, even better, but only if you're using C# 6
string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";
Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.