From 89dd4d3271c58d0f47d72c9c811c1cd0eac18188 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 23 May 2023 13:48:37 +0300 Subject: [PATCH] Inline 'out' variable declarations (cherry picked from commit 281add47de1d3940990156c841362125dea9cc7d) Closes #2558 --- src/NzbDrone.Common/Cache/Cached.cs | 10 +++------- src/NzbDrone.Common/Cache/CachedDictionary.cs | 13 ++++--------- .../Extensions/TryParseExtensions.cs | 12 +++--------- .../Http/TooManyRequestsException.cs | 6 ++---- .../Configuration/ConfigFileProvider.cs | 3 +-- src/NzbDrone.Core/Configuration/ConfigService.cs | 7 ++----- .../DownloadStation/TorrentDownloadStation.cs | 6 ++---- .../DownloadStation/UsenetDownloadStation.cs | 6 ++---- .../NzbVortexLoginResultTypeConverter.cs | 3 +-- .../NzbVortexResultTypeConverter.cs | 3 +-- .../Download/Clients/NzbVortex/NzbVortex.cs | 4 +--- .../Download/Clients/Nzbget/Nzbget.cs | 3 +-- .../Download/Clients/Nzbget/NzbgetProxy.cs | 3 +-- .../SabnzbdPriorityTypeConverter.cs | 3 +-- .../Download/Clients/Sabnzbd/SabnzbdProxy.cs | 16 ++++------------ src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs | 5 ++--- .../Download/DownloadClientFactory.cs | 3 +-- .../Download/Pending/PendingReleaseService.cs | 3 +-- .../HealthCheck/HealthCheckService.cs | 3 +-- .../ImportLists/ImportListFactory.cs | 3 +-- src/NzbDrone.Core/Indexers/IndexerFactory.cs | 3 +-- .../Indexers/Newznab/NewznabRssParser.cs | 4 +--- .../Indexers/Torznab/TorznabRssParser.cs | 4 +--- src/NzbDrone.Core/Indexers/XElementExtensions.cs | 5 ++--- .../Messaging/Events/EventAggregator.cs | 3 +-- .../Goodreads/Extensions/XmlExtensions.cs | 11 +++++------ .../Goodreads/Resources/BookResource.cs | 3 +-- .../Goodreads/Resources/WorkResource.cs | 5 ++--- .../Notifications/PushBullet/PushBulletProxy.cs | 3 +-- src/NzbDrone.Core/Parser/Parser.cs | 16 +++++----------- .../Profiles/Releases/TermMatcherService.cs | 4 +--- .../DiskProviderTests/DiskProviderFixture.cs | 3 +-- src/NzbDrone.Mono/Disk/DiskProvider.cs | 8 ++------ src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs | 4 +--- src/NzbDrone.Test.Common/LoggingTest.cs | 3 +-- src/NzbDrone.Update/UpdateApp.cs | 3 +-- src/NzbDrone.Windows/Disk/DiskProvider.cs | 15 +++------------ src/Readarr.Http/ClientSchema/SchemaBuilder.cs | 3 +-- 38 files changed, 66 insertions(+), 149 deletions(-) diff --git a/src/NzbDrone.Common/Cache/Cached.cs b/src/NzbDrone.Common/Cache/Cached.cs index a22c9ade3..02f6fa575 100644 --- a/src/NzbDrone.Common/Cache/Cached.cs +++ b/src/NzbDrone.Common/Cache/Cached.cs @@ -54,8 +54,7 @@ namespace NzbDrone.Common.Cache public T Find(string key) { - CacheItem cacheItem; - if (!_store.TryGetValue(key, out cacheItem)) + if (!_store.TryGetValue(key, out var cacheItem)) { return default(T); } @@ -84,8 +83,7 @@ namespace NzbDrone.Common.Cache public void Remove(string key) { - CacheItem value; - _store.TryRemove(key, out value); + _store.TryRemove(key, out _); } public int Count => _store.Count; @@ -96,9 +94,7 @@ namespace NzbDrone.Common.Cache lifeTime = lifeTime ?? _defaultLifeTime; - CacheItem cacheItem; - - if (_store.TryGetValue(key, out cacheItem) && !cacheItem.IsExpired()) + if (_store.TryGetValue(key, out var cacheItem) && !cacheItem.IsExpired()) { if (_rollingExpiry && lifeTime.HasValue) { diff --git a/src/NzbDrone.Common/Cache/CachedDictionary.cs b/src/NzbDrone.Common/Cache/CachedDictionary.cs index 6332f5054..922b45835 100644 --- a/src/NzbDrone.Common/Cache/CachedDictionary.cs +++ b/src/NzbDrone.Common/Cache/CachedDictionary.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -86,9 +86,7 @@ namespace NzbDrone.Common.Cache { RefreshIfExpired(); - TValue result; - - if (!_items.TryGetValue(key, out result)) + if (!_items.TryGetValue(key, out var result)) { throw new KeyNotFoundException(string.Format("Item {0} not found in cache.", key)); } @@ -100,9 +98,7 @@ namespace NzbDrone.Common.Cache { RefreshIfExpired(); - TValue result; - - _items.TryGetValue(key, out result); + _items.TryGetValue(key, out var result); return result; } @@ -128,8 +124,7 @@ namespace NzbDrone.Common.Cache public void Remove(string key) { - TValue item; - _items.TryRemove(key, out item); + _items.TryRemove(key, out _); } } } diff --git a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs index 1ed79c319..3b9f3db49 100644 --- a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs +++ b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs @@ -6,9 +6,7 @@ namespace NzbDrone.Common.Extensions { public static int? ParseInt32(this string source) { - int result; - - if (int.TryParse(source, out result)) + if (int.TryParse(source, out var result)) { return result; } @@ -18,9 +16,7 @@ namespace NzbDrone.Common.Extensions public static long? ParseInt64(this string source) { - long result; - - if (long.TryParse(source, out result)) + if (long.TryParse(source, out var result)) { return result; } @@ -30,9 +26,7 @@ namespace NzbDrone.Common.Extensions public static double? ParseDouble(this string source) { - double result; - - if (double.TryParse(source.Replace(',', '.'), NumberStyles.Number, CultureInfo.InvariantCulture, out result)) + if (double.TryParse(source.Replace(',', '.'), NumberStyles.Number, CultureInfo.InvariantCulture, out var result)) { return result; } diff --git a/src/NzbDrone.Common/Http/TooManyRequestsException.cs b/src/NzbDrone.Common/Http/TooManyRequestsException.cs index 117188b4e..c276ef128 100644 --- a/src/NzbDrone.Common/Http/TooManyRequestsException.cs +++ b/src/NzbDrone.Common/Http/TooManyRequestsException.cs @@ -12,14 +12,12 @@ namespace NzbDrone.Common.Http if (response.Headers.ContainsKey("Retry-After")) { var retryAfter = response.Headers["Retry-After"].ToString(); - int seconds; - DateTime date; - if (int.TryParse(retryAfter, out seconds)) + if (int.TryParse(retryAfter, out var seconds)) { RetryAfter = TimeSpan.FromSeconds(seconds); } - else if (DateTime.TryParse(retryAfter, out date)) + else if (DateTime.TryParse(retryAfter, out var date)) { RetryAfter = date.ToUniversalTime() - DateTime.UtcNow; } diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index 905c5eb06..f76a60b63 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -117,8 +117,7 @@ namespace NzbDrone.Core.Configuration continue; } - object currentValue; - allWithDefaults.TryGetValue(configValue.Key, out currentValue); + allWithDefaults.TryGetValue(configValue.Key, out var currentValue); if (currentValue == null) { continue; diff --git a/src/NzbDrone.Core/Configuration/ConfigService.cs b/src/NzbDrone.Core/Configuration/ConfigService.cs index 85b8268e9..1fcabfdc1 100644 --- a/src/NzbDrone.Core/Configuration/ConfigService.cs +++ b/src/NzbDrone.Core/Configuration/ConfigService.cs @@ -56,8 +56,7 @@ namespace NzbDrone.Core.Configuration foreach (var configValue in configValues) { - object currentValue; - allWithDefaults.TryGetValue(configValue.Key, out currentValue); + allWithDefaults.TryGetValue(configValue.Key, out var currentValue); if (currentValue == null || configValue.Value == null) { continue; @@ -439,9 +438,7 @@ namespace NzbDrone.Core.Configuration EnsureCache(); - string dbValue; - - if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !string.IsNullOrEmpty(dbValue)) + if (_cache.TryGetValue(key, out var dbValue) && dbValue != null && !string.IsNullOrEmpty(dbValue)) { return dbValue; } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 3747ec4e7..d5f5e4965 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -254,9 +254,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetRemainingSize(DownloadStationTask torrent) { var downloadedString = torrent.Additional.Transfer["size_downloaded"]; - long downloadedSize; - if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out downloadedSize)) + if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out var downloadedSize)) { _logger.Debug("Torrent {0} has invalid size_downloaded: {1}", torrent.Title, downloadedString); downloadedSize = 0; @@ -268,9 +267,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected TimeSpan? GetRemainingTime(DownloadStationTask torrent) { var speedString = torrent.Additional.Transfer["speed_download"]; - long downloadSpeed; - if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out downloadSpeed)) + if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out var downloadSpeed)) { _logger.Debug("Torrent {0} has invalid speed_download: {1}", torrent.Title, speedString); downloadSpeed = 0; diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index 753a845be..792e983ca 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -351,9 +351,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetRemainingSize(DownloadStationTask task) { var downloadedString = task.Additional.Transfer["size_downloaded"]; - long downloadedSize; - if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out downloadedSize)) + if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out var downloadedSize)) { _logger.Debug("Task {0} has invalid size_downloaded: {1}", task.Title, downloadedString); downloadedSize = 0; @@ -365,9 +364,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetDownloadSpeed(DownloadStationTask task) { var speedString = task.Additional.Transfer["speed_download"]; - long downloadSpeed; - if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out downloadSpeed)) + if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out var downloadSpeed)) { _logger.Debug("Task {0} has invalid speed_download: {1}", task.Title, speedString); downloadSpeed = 0; diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs index e74b8f973..7f0f27de7 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex.JsonConverters { var result = reader.Value.ToString().Replace("_", string.Empty); - NzbVortexLoginResultType output; - Enum.TryParse(result, true, out output); + Enum.TryParse(result, true, out NzbVortexLoginResultType output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs index bd63788bc..aa515abdb 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex.JsonConverters { var result = reader.Value.ToString().Replace("_", string.Empty); - NzbVortexResultType output; - Enum.TryParse(result, true, out output); + Enum.TryParse(result, true, out NzbVortexResultType output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs index f49e9c2ac..705d21393 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs @@ -113,9 +113,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex public override void RemoveItem(DownloadClientItem item, bool deleteData) { // Try to find the download by numerical ID, otherwise try by AddUUID - int id; - - if (int.TryParse(item.DownloadId, out id)) + if (int.TryParse(item.DownloadId, out var id)) { _proxy.Remove(id, deleteData, Settings); } diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index 1b48b9671..f97a26ec9 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -310,8 +310,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget var config = _proxy.GetConfig(Settings); var keepHistory = config.GetValueOrDefault("KeepHistory", "7"); - int value; - if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out value) || value == 0) + if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out var value) || value == 0) { return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0") { diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs index 9e81eeaba..1634f53a4 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs @@ -164,11 +164,10 @@ namespace NzbDrone.Core.Download.Clients.Nzbget var queue = GetQueue(settings); var history = GetHistory(settings); - int nzbId; NzbgetQueueItem queueItem; NzbgetHistoryItem historyItem; - if (id.Length < 10 && int.TryParse(id, out nzbId)) + if (id.Length < 10 && int.TryParse(id, out var nzbId)) { // Download wasn't grabbed by Readarr, so the id is the NzbId reported by nzbget. queueItem = queue.SingleOrDefault(h => h.NzbId == nzbId); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs index 246b5b558..f29317251 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters { var queuePriority = reader.Value.ToString(); - SabnzbdPriority output; - Enum.TryParse(queuePriority, out output); + Enum.TryParse(queuePriority, out SabnzbdPriority output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index 701ac1fbe..ceb168f84 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -51,9 +51,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd request.AddFormUpload("name", filename, nzbData, "application/x-nzb"); - SabnzbdAddResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdAddResponse(); response.Status = true; @@ -76,9 +74,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { var request = BuildRequest("version", settings); - SabnzbdVersionResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdVersionResponse(); } @@ -142,9 +138,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd var request = BuildRequest("retry", settings); request.AddQueryParam("value", id); - SabnzbdRetryResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdRetryResponse(); response.Status = true; @@ -215,9 +209,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd private void CheckForError(HttpResponse response) { - SabnzbdJsonError result; - - if (!Json.TryDeserialize(response.Content, out result)) + if (!Json.TryDeserialize(response.Content, out var result)) { //Handle plain text responses from SAB result = new SabnzbdJsonError(); diff --git a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs index d287e0c67..fda64aa05 100644 --- a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs +++ b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs @@ -1,4 +1,4 @@ -using FluentValidation.Results; +using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; @@ -54,8 +54,7 @@ namespace NzbDrone.Core.Download.Clients.Vuze _logger.Debug("Vuze protocol version information: {0}", versionString); - int version; - if (!int.TryParse(versionString, out version) || version < MINIMUM_SUPPORTED_PROTOCOL_VERSION) + if (!int.TryParse(versionString, out var version) || version < MINIMUM_SUPPORTED_PROTOCOL_VERSION) { { return new ValidationFailure(string.Empty, "Protocol version not supported, use Vuze 5.0.0.0 or higher with Vuze Web Remote plugin."); diff --git a/src/NzbDrone.Core/Download/DownloadClientFactory.cs b/src/NzbDrone.Core/Download/DownloadClientFactory.cs index 3a4ab734a..3c7d4c3b5 100644 --- a/src/NzbDrone.Core/Download/DownloadClientFactory.cs +++ b/src/NzbDrone.Core/Download/DownloadClientFactory.cs @@ -60,8 +60,7 @@ namespace NzbDrone.Core.Download foreach (var client in clients) { - DownloadClientStatus downloadClientStatus; - if (blockedIndexers.TryGetValue(client.Definition.Id, out downloadClientStatus)) + if (blockedIndexers.TryGetValue(client.Definition.Id, out var downloadClientStatus)) { _logger.Debug("Temporarily ignoring download client {0} till {1} due to recent failures.", client.Definition.Name, downloadClientStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index 2dcdaf3a2..db51a324e 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -307,8 +307,7 @@ namespace NzbDrone.Core.Download.Pending List books; - RemoteBook knownRemoteBook; - if (knownRemoteBooks != null && knownRemoteBooks.TryGetValue(release.Release.Title, out knownRemoteBook)) + if (knownRemoteBooks != null && knownRemoteBooks.TryGetValue(release.Release.Title, out var knownRemoteBook)) { books = knownRemoteBook.Books; } diff --git a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs index 36bc6e969..fde60d593 100644 --- a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs +++ b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs @@ -164,8 +164,7 @@ namespace NzbDrone.Core.HealthCheck _isRunningHealthChecksAfterGracePeriod = false; } - IEventDrivenHealthCheck[] checks; - if (!_eventDrivenHealthChecks.TryGetValue(message.GetType(), out checks)) + if (!_eventDrivenHealthChecks.TryGetValue(message.GetType(), out var checks)) { return; } diff --git a/src/NzbDrone.Core/ImportLists/ImportListFactory.cs b/src/NzbDrone.Core/ImportLists/ImportListFactory.cs index 12ca6ce20..5ac6135c1 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListFactory.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListFactory.cs @@ -61,8 +61,7 @@ namespace NzbDrone.Core.ImportLists foreach (var importList in importLists) { - ImportListStatus blockedImportListStatus; - if (blockedImportLists.TryGetValue(importList.Definition.Id, out blockedImportListStatus)) + if (blockedImportLists.TryGetValue(importList.Definition.Id, out var blockedImportListStatus)) { _logger.Debug("Temporarily ignoring import list {0} till {1} due to recent failures.", importList.Definition.Name, blockedImportListStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/Indexers/IndexerFactory.cs b/src/NzbDrone.Core/Indexers/IndexerFactory.cs index 4e72a36cd..58f3a3f68 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFactory.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFactory.cs @@ -88,8 +88,7 @@ namespace NzbDrone.Core.Indexers foreach (var indexer in indexers) { - IndexerStatus blockedIndexerStatus; - if (blockedIndexers.TryGetValue(indexer.Definition.Id, out blockedIndexerStatus)) + if (blockedIndexers.TryGetValue(indexer.Definition.Id, out var blockedIndexerStatus)) { _logger.Debug("Temporarily ignoring indexer {0} till {1} due to recent failures.", indexer.Definition.Name, blockedIndexerStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index c4b45f30b..c3949e86b 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -129,10 +129,8 @@ namespace NzbDrone.Core.Indexers.Newznab protected override long GetSize(XElement item) { - long size; - var sizeString = TryGetNewznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out var size)) { return size; } diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs index e056dded4..4a441f35d 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs @@ -110,10 +110,8 @@ namespace NzbDrone.Core.Indexers.Torznab protected override long GetSize(XElement item) { - long size; - var sizeString = TryGetTorznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out var size)) { return size; } diff --git a/src/NzbDrone.Core/Indexers/XElementExtensions.cs b/src/NzbDrone.Core/Indexers/XElementExtensions.cs index a90dbed85..9e8b83f9f 100644 --- a/src/NzbDrone.Core/Indexers/XElementExtensions.cs +++ b/src/NzbDrone.Core/Indexers/XElementExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -39,8 +39,7 @@ namespace NzbDrone.Core.Indexers { try { - DateTime result; - if (!DateTime.TryParse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out result)) + if (!DateTime.TryParse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out var result)) { dateString = RemoveTimeZoneRegex.Replace(dateString, ""); result = DateTime.Parse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal); diff --git a/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs b/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs index e492381de..c8fa4a1db 100644 --- a/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs +++ b/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs @@ -76,8 +76,7 @@ namespace NzbDrone.Core.Messaging.Events EventSubscribers subscribers; lock (_eventSubscribers) { - object target; - if (!_eventSubscribers.TryGetValue(eventName, out target)) + if (!_eventSubscribers.TryGetValue(eventName, out var target)) { _eventSubscribers[eventName] = target = new EventSubscribers(_serviceFactory); } diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/Extensions/XmlExtensions.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/Extensions/XmlExtensions.cs index d1845d97a..d1fa80361 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/Extensions/XmlExtensions.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/Extensions/XmlExtensions.cs @@ -73,13 +73,12 @@ namespace NzbDrone.Core.MetadataSource.Goodreads // This regex corrects the format and hopefully doesn't mess anything else up... var validDateFormat = Regex.Replace(value, @"(.*) ([+-]\d{2})(\d{2}) (.*)", "$1 $2:$3 $4"); - DateTime localDate; if (DateTime.TryParseExact( - validDateFormat, - "ddd MMM dd HH:mm:ss zzz yyyy", - CultureInfo.InvariantCulture, - DateTimeStyles.None, - out localDate)) + validDateFormat, + "ddd MMM dd HH:mm:ss zzz yyyy", + CultureInfo.InvariantCulture, + DateTimeStyles.None, + out var localDate)) { return localDate.ToUniversalTime(); } diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/BookResource.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/BookResource.cs index 2867a6db5..29f3f4dc6 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/BookResource.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/BookResource.cs @@ -227,8 +227,7 @@ namespace NzbDrone.Core.MetadataSource.Goodreads var shelfName = shelfElement?.Attribute("name")?.Value; var shelfCountValue = shelfElement?.Attribute("count")?.Value; - int shelfCount = 0; - int.TryParse(shelfCountValue, out shelfCount); + int.TryParse(shelfCountValue, out var shelfCount); return new KeyValuePair(shelfName, shelfCount); }); diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs index a521bbb8a..e0c5913db 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/Resources/WorkResource.cs @@ -144,9 +144,8 @@ namespace NzbDrone.Core.MetadataSource.Goodreads foreach (var rating in ratings) { - int star = 0, count = 0; - int.TryParse(rating[0], out star); - int.TryParse(rating[1], out count); + int.TryParse(rating[0], out var star); + int.TryParse(rating[1], out var count); ratingDistribution.Add(star, count); } diff --git a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs index 1f3cb4ce8..e65ba86ad 100644 --- a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs +++ b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs @@ -152,14 +152,13 @@ namespace NzbDrone.Core.Notifications.PushBullet private HttpRequestBuilder BuildDeviceRequest(string deviceId) { var requestBuilder = new HttpRequestBuilder(PUSH_URL).Post(); - long integerId; if (deviceId.IsNullOrWhiteSpace()) { return requestBuilder; } - if (long.TryParse(deviceId, out integerId)) + if (long.TryParse(deviceId, out var integerId)) { requestBuilder.AddFormParameter("device_id", integerId); } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index f9996ff28..90bdd0676 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -647,9 +647,8 @@ namespace NzbDrone.Core.Parser if (matches.Count != 0) { var group = matches.OfType().Last().Groups["releasegroup"].Value; - int groupIsNumeric; - if (int.TryParse(group, out groupIsNumeric)) + if (int.TryParse(group, out _)) { return null; } @@ -792,8 +791,7 @@ namespace NzbDrone.Core.Parser bookTitle = RequestInfoRegex.Replace(bookTitle, "").Trim(' '); releaseVersion = RequestInfoRegex.Replace(releaseVersion, "").Trim(' '); - int releaseYear; - int.TryParse(matchCollection[0].Groups["releaseyear"].Value, out releaseYear); + int.TryParse(matchCollection[0].Groups["releaseyear"].Value, out var releaseYear); ParsedBookInfo result; @@ -810,10 +808,8 @@ namespace NzbDrone.Core.Parser if (matchCollection[0].Groups["discography"].Success) { - int discStart; - int discEnd; - int.TryParse(matchCollection[0].Groups["startyear"].Value, out discStart); - int.TryParse(matchCollection[0].Groups["endyear"].Value, out discEnd); + int.TryParse(matchCollection[0].Groups["startyear"].Value, out var discStart); + int.TryParse(matchCollection[0].Groups["endyear"].Value, out var discEnd); result.Discography = true; if (discStart > 0 && discEnd > 0) @@ -891,9 +887,7 @@ namespace NzbDrone.Core.Parser private static int ParseNumber(string value) { - int number; - - if (int.TryParse(value, out number)) + if (int.TryParse(value, out var number)) { return number; } diff --git a/src/NzbDrone.Core/Profiles/Releases/TermMatcherService.cs b/src/NzbDrone.Core/Profiles/Releases/TermMatcherService.cs index 70edccdc9..69df8e450 100644 --- a/src/NzbDrone.Core/Profiles/Releases/TermMatcherService.cs +++ b/src/NzbDrone.Core/Profiles/Releases/TermMatcherService.cs @@ -1,5 +1,4 @@ using System; -using System.Text.RegularExpressions; using NzbDrone.Common.Cache; using NzbDrone.Core.Profiles.Releases.TermMatchers; @@ -37,8 +36,7 @@ namespace NzbDrone.Core.Profiles.Releases private ITermMatcher CreateMatcherInternal(string term) { - Regex regex; - if (PerlRegexFactory.TryCreateRegex(term, out regex)) + if (PerlRegexFactory.TryCreateRegex(term, out var regex)) { return new RegexTermMatcher(regex); } diff --git a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs index cb804ecf4..25a02fd43 100644 --- a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs +++ b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs @@ -57,8 +57,7 @@ namespace NzbDrone.Mono.Test.DiskProviderTests protected void SetWritePermissionsInternal(string path, bool writable, bool setgid) { // Remove Write permissions, we're still owner so we can clean it up, but we'll have to do that explicitly. - Stat stat; - Syscall.stat(path, out stat); + Syscall.stat(path, out var stat); FilePermissions mode = stat.st_mode; if (writable) diff --git a/src/NzbDrone.Mono/Disk/DiskProvider.cs b/src/NzbDrone.Mono/Disk/DiskProvider.cs index a774b79c7..c8c4b440e 100644 --- a/src/NzbDrone.Mono/Disk/DiskProvider.cs +++ b/src/NzbDrone.Mono/Disk/DiskProvider.cs @@ -489,9 +489,7 @@ namespace NzbDrone.Mono.Disk return UNCHANGED_ID; } - uint userId; - - if (uint.TryParse(user, out userId)) + if (uint.TryParse(user, out var userId)) { return userId; } @@ -513,9 +511,7 @@ namespace NzbDrone.Mono.Disk return UNCHANGED_ID; } - uint groupId; - - if (uint.TryParse(group, out groupId)) + if (uint.TryParse(group, out var groupId)) { return groupId; } diff --git a/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs b/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs index a190fc1ce..59f824c8d 100644 --- a/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs +++ b/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs @@ -83,9 +83,7 @@ namespace NzbDrone.Mono.Disk private bool TryFollowFirstSymbolicLink(ref string path) { - string[] dirs; - int lastIndex; - GetPathComponents(path, out dirs, out lastIndex); + GetPathComponents(path, out var dirs, out var lastIndex); if (lastIndex == 0) { diff --git a/src/NzbDrone.Test.Common/LoggingTest.cs b/src/NzbDrone.Test.Common/LoggingTest.cs index 02b064d94..6b0dfa198 100644 --- a/src/NzbDrone.Test.Common/LoggingTest.cs +++ b/src/NzbDrone.Test.Common/LoggingTest.cs @@ -23,8 +23,7 @@ namespace NzbDrone.Test.Common { LogManager.Configuration = new LoggingConfiguration(); - var logOutput = TestLogOutput.Console; - Enum.TryParse(Environment.GetEnvironmentVariable("READARR_TESTS_LOG_OUTPUT"), out logOutput); + Enum.TryParse(Environment.GetEnvironmentVariable("READARR_TESTS_LOG_OUTPUT"), out var logOutput); RegisterSentryLogger(); diff --git a/src/NzbDrone.Update/UpdateApp.cs b/src/NzbDrone.Update/UpdateApp.cs index 929392358..fc1abeacb 100644 --- a/src/NzbDrone.Update/UpdateApp.cs +++ b/src/NzbDrone.Update/UpdateApp.cs @@ -100,8 +100,7 @@ namespace NzbDrone.Update private int ParseProcessId(string arg) { - int id; - if (!int.TryParse(arg, out id) || id <= 0) + if (!int.TryParse(arg, out var id) || id <= 0) { throw new ArgumentOutOfRangeException(nameof(arg), "Invalid process ID"); } diff --git a/src/NzbDrone.Windows/Disk/DiskProvider.cs b/src/NzbDrone.Windows/Disk/DiskProvider.cs index 55a2efbaa..1e8c310e1 100644 --- a/src/NzbDrone.Windows/Disk/DiskProvider.cs +++ b/src/NzbDrone.Windows/Disk/DiskProvider.cs @@ -87,8 +87,7 @@ namespace NzbDrone.Windows.Disk PropagationFlags.InheritOnly, controlType); - bool modified; - directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out modified); + directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out var modified); if (modified) { @@ -137,11 +136,7 @@ namespace NzbDrone.Windows.Disk folderName += '\\'; } - ulong free = 0; - ulong dummy1 = 0; - ulong dummy2 = 0; - - if (GetDiskFreeSpaceEx(folderName, out free, out dummy1, out dummy2)) + if (GetDiskFreeSpaceEx(folderName, out var free, out var dummy1, out var dummy2)) { return (long)free; } @@ -158,11 +153,7 @@ namespace NzbDrone.Windows.Disk folderName += '\\'; } - ulong total = 0; - ulong dummy1 = 0; - ulong dummy2 = 0; - - if (GetDiskFreeSpaceEx(folderName, out dummy1, out total, out dummy2)) + if (GetDiskFreeSpaceEx(folderName, out var dummy1, out var total, out var dummy2)) { return (long)total; } diff --git a/src/Readarr.Http/ClientSchema/SchemaBuilder.cs b/src/Readarr.Http/ClientSchema/SchemaBuilder.cs index a1663a28a..d53ddb831 100644 --- a/src/Readarr.Http/ClientSchema/SchemaBuilder.cs +++ b/src/Readarr.Http/ClientSchema/SchemaBuilder.cs @@ -66,8 +66,7 @@ namespace Readarr.Http.ClientSchema { lock (_mappings) { - FieldMapping[] result; - if (!_mappings.TryGetValue(type, out result)) + if (!_mappings.TryGetValue(type, out var result)) { result = GetFieldMapping(type, "", v => v);