1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Replaced manual argument validations with Ensure.

This commit is contained in:
kayone 2013-12-02 22:41:40 -08:00
parent b055fc5ade
commit 76bc4aaa9c
4 changed files with 9 additions and 17 deletions

View File

@ -506,10 +506,7 @@ public string GetVolumeLabel(string path)
private static long DriveFreeSpaceEx(string folderName) private static long DriveFreeSpaceEx(string folderName)
{ {
if (string.IsNullOrEmpty(folderName)) Ensure.That(folderName, () => folderName).IsValidPath();
{
throw new ArgumentNullException("folderName");
}
if (!folderName.EndsWith("\\")) if (!folderName.EndsWith("\\"))
{ {
@ -530,10 +527,7 @@ private static long DriveFreeSpaceEx(string folderName)
private static long DriveTotalSizeEx(string folderName) private static long DriveTotalSizeEx(string folderName)
{ {
if (string.IsNullOrEmpty(folderName)) Ensure.That(folderName, () => folderName).IsValidPath();
{
throw new ArgumentNullException("folderName");
}
if (!folderName.EndsWith("\\")) if (!folderName.EndsWith("\\"))
{ {

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Nzbget;
@ -305,9 +306,11 @@ public T GetValueEnum<T>(string key, T defaultValue)
public string GetValue(string key, object defaultValue, bool persist = false) public string GetValue(string key, object defaultValue, bool persist = false)
{ {
key = key.ToLowerInvariant();
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
EnsureCache(); EnsureCache();
key = key.ToLowerInvariant();
string dbValue; string dbValue;
if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !String.IsNullOrEmpty(dbValue)) if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !String.IsNullOrEmpty(dbValue))
@ -336,11 +339,6 @@ public void SetValue(string key, string value)
{ {
key = key.ToLowerInvariant(); key = key.ToLowerInvariant();
if (String.IsNullOrEmpty(key))
throw new ArgumentOutOfRangeException("key");
if (value == null)
throw new ArgumentNullException("key");
_logger.Trace("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value); _logger.Trace("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
var dbValue = _repository.Get(key); var dbValue = _repository.Get(key);

View File

@ -20,7 +20,6 @@ public XemService(IEpisodeService episodeService,
IXemProxy xemProxy, IXemProxy xemProxy,
ISeriesService seriesService, ICacheManger cacheManger, Logger logger) ISeriesService seriesService, ICacheManger cacheManger, Logger logger)
{ {
if (seriesService == null) throw new ArgumentNullException("seriesService");
_episodeService = episodeService; _episodeService = episodeService;
_xemProxy = xemProxy; _xemProxy = xemProxy;
_seriesService = seriesService; _seriesService = seriesService;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NzbDrone.Common.EnsureThat;
namespace NzbDrone.Core namespace NzbDrone.Core
{ {
@ -9,8 +10,8 @@ public static class Fluent
{ {
public static string WithDefault(this string actual, object defaultValue) public static string WithDefault(this string actual, object defaultValue)
{ {
if (defaultValue == null) Ensure.That(defaultValue, () => defaultValue).IsNotNull();
throw new ArgumentNullException("defaultValue");
if (String.IsNullOrWhiteSpace(actual)) if (String.IsNullOrWhiteSpace(actual))
{ {
return defaultValue.ToString(); return defaultValue.ToString();