From 76bc4aaa9ce851b5df58f7883185198a7a2cca8c Mon Sep 17 00:00:00 2001 From: kayone Date: Mon, 2 Dec 2013 22:41:40 -0800 Subject: [PATCH] Replaced manual argument validations with Ensure. --- src/NzbDrone.Common/DiskProvider.cs | 10 ++-------- src/NzbDrone.Core/Configuration/ConfigService.cs | 10 ++++------ src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs | 1 - src/NzbDrone.Core/Fluent.cs | 5 +++-- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/NzbDrone.Common/DiskProvider.cs b/src/NzbDrone.Common/DiskProvider.cs index ef5242fc7..13379c91c 100644 --- a/src/NzbDrone.Common/DiskProvider.cs +++ b/src/NzbDrone.Common/DiskProvider.cs @@ -506,10 +506,7 @@ namespace NzbDrone.Common private static long DriveFreeSpaceEx(string folderName) { - if (string.IsNullOrEmpty(folderName)) - { - throw new ArgumentNullException("folderName"); - } + Ensure.That(folderName, () => folderName).IsValidPath(); if (!folderName.EndsWith("\\")) { @@ -530,10 +527,7 @@ namespace NzbDrone.Common private static long DriveTotalSizeEx(string folderName) { - if (string.IsNullOrEmpty(folderName)) - { - throw new ArgumentNullException("folderName"); - } + Ensure.That(folderName, () => folderName).IsValidPath(); if (!folderName.EndsWith("\\")) { diff --git a/src/NzbDrone.Core/Configuration/ConfigService.cs b/src/NzbDrone.Core/Configuration/ConfigService.cs index 89f542670..373385aa2 100644 --- a/src/NzbDrone.Core/Configuration/ConfigService.cs +++ b/src/NzbDrone.Core/Configuration/ConfigService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.EnsureThat; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Nzbget; @@ -305,9 +306,11 @@ namespace NzbDrone.Core.Configuration public string GetValue(string key, object defaultValue, bool persist = false) { + key = key.ToLowerInvariant(); + Ensure.That(key, () => key).IsNotNullOrWhiteSpace(); + EnsureCache(); - key = key.ToLowerInvariant(); string dbValue; if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !String.IsNullOrEmpty(dbValue)) @@ -336,11 +339,6 @@ namespace NzbDrone.Core.Configuration { 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); var dbValue = _repository.Get(key); diff --git a/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs b/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs index c7e7b3441..f8dfed427 100644 --- a/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Xem/XemService.cs @@ -20,7 +20,6 @@ namespace NzbDrone.Core.DataAugmentation.Xem IXemProxy xemProxy, ISeriesService seriesService, ICacheManger cacheManger, Logger logger) { - if (seriesService == null) throw new ArgumentNullException("seriesService"); _episodeService = episodeService; _xemProxy = xemProxy; _seriesService = seriesService; diff --git a/src/NzbDrone.Core/Fluent.cs b/src/NzbDrone.Core/Fluent.cs index 8ec82a8ab..b7ae4824b 100644 --- a/src/NzbDrone.Core/Fluent.cs +++ b/src/NzbDrone.Core/Fluent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using NzbDrone.Common.EnsureThat; namespace NzbDrone.Core { @@ -9,8 +10,8 @@ namespace NzbDrone.Core { public static string WithDefault(this string actual, object defaultValue) { - if (defaultValue == null) - throw new ArgumentNullException("defaultValue"); + Ensure.That(defaultValue, () => defaultValue).IsNotNull(); + if (String.IsNullOrWhiteSpace(actual)) { return defaultValue.ToString();