Changed: Align GetValueOrDefault extension with netcore3.0 version

- netcore3.0 implements the extenion on IReadOnlyDictionary.
 - Dictionary implements both IReadonlyDictionary and IDictionary and
   so defining the extenion on both interfaces creates an ambiguous
   reference
 - IDictionary doesn't inherit from IReadOnlyDictionary

Either we have to add 'using NzbDrone.Common.Extenions;'
separately to resolve the ambiguity or we have to standardaize on only
having the extension on IReadOnlyDictionary.
pull/2/head
ta264 5 years ago committed by Qstick
parent 057829c3b0
commit b5b43b8b3f

@ -6,11 +6,13 @@ namespace NzbDrone.Common.Extensions
{ {
public static class DictionaryExtensions public static class DictionaryExtensions
{ {
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue)) #if !NETCOREAPP3_0
public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
{ {
TValue value; TValue value;
return dictionary.TryGetValue(key, out value) ? value : defaultValue; return dictionary.TryGetValue(key, out value) ? value : defaultValue;
} }
#endif
public static Dictionary<T1, T2> Merge<T1, T2>(this Dictionary<T1, T2> first, Dictionary<T1, T2> second) public static Dictionary<T1, T2> Merge<T1, T2>(this Dictionary<T1, T2> first, Dictionary<T1, T2> second)
{ {

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;

@ -1,23 +1,21 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.MediaFiles.TorrentInfo;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Validation;
using NLog;
using FluentValidation.Results;
using System.Net;
using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Download.Clients.Deluge namespace NzbDrone.Core.Download.Clients.Deluge
{ {
// this is here to resolve ambiguity in GetValueOrDefault extension method in net core 3
using NzbDrone.Common.Extensions;
public class Deluge : TorrentClientBase<DelugeSettings> public class Deluge : TorrentClientBase<DelugeSettings>
{ {
private readonly IDelugeProxy _proxy; private readonly IDelugeProxy _proxy;

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
{ {
HadoukenSystemInfo GetSystemInfo(HadoukenSettings settings); HadoukenSystemInfo GetSystemInfo(HadoukenSettings settings);
HadoukenTorrent[] GetTorrents(HadoukenSettings settings); HadoukenTorrent[] GetTorrents(HadoukenSettings settings);
IDictionary<string, object> GetConfig(HadoukenSettings settings); IReadOnlyDictionary<string, object> GetConfig(HadoukenSettings settings);
string AddTorrentFile(HadoukenSettings settings, byte[] fileContent); string AddTorrentFile(HadoukenSettings settings, byte[] fileContent);
void AddTorrentUri(HadoukenSettings settings, string torrentUrl); void AddTorrentUri(HadoukenSettings settings, string torrentUrl);
void RemoveTorrent(HadoukenSettings settings, string downloadId); void RemoveTorrent(HadoukenSettings settings, string downloadId);
@ -42,9 +42,9 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
return GetTorrents(result.Torrents); return GetTorrents(result.Torrents);
} }
public IDictionary<string, object> GetConfig(HadoukenSettings settings) public IReadOnlyDictionary<string, object> GetConfig(HadoukenSettings settings)
{ {
return ProcessRequest<IDictionary<string, object>>(settings, "webui.getSettings"); return ProcessRequest<IReadOnlyDictionary<string, object>>(settings, "webui.getSettings");
} }
public string AddTorrentFile(HadoukenSettings settings, byte[] fileContent) public string AddTorrentFile(HadoukenSettings settings, byte[] fileContent)

@ -6,6 +6,7 @@ using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
@ -16,9 +17,6 @@ using NzbDrone.Core.Organizer;
namespace NzbDrone.Core.Download.Clients.Nzbget namespace NzbDrone.Core.Download.Clients.Nzbget
{ {
// this is here to resolve ambiguity in GetValueOrDefault extension method in net core 3
using NzbDrone.Common.Extensions;
public class Nzbget : UsenetClientBase<NzbgetSettings> public class Nzbget : UsenetClientBase<NzbgetSettings>
{ {
private readonly INzbgetProxy _proxy; private readonly INzbgetProxy _proxy;

@ -311,7 +311,7 @@ namespace NzbDrone.Core.Organizer
} }
private const string MediaInfoVideoDynamicRangeToken = "{MediaInfo VideoDynamicRange}"; private const string MediaInfoVideoDynamicRangeToken = "{MediaInfo VideoDynamicRange}";
private static readonly IDictionary<string, int> MinimumMediaInfoSchemaRevisions = private static readonly IReadOnlyDictionary<string, int> MinimumMediaInfoSchemaRevisions =
new Dictionary<string, int>(FileNameBuilderTokenEqualityComparer.Instance) new Dictionary<string, int>(FileNameBuilderTokenEqualityComparer.Instance)
{ {
{MediaInfoVideoDynamicRangeToken, 5} {MediaInfoVideoDynamicRangeToken, 5}

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Parser.Model
/// It is expanded by the augmenters. /// It is expanded by the augmenters.
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public IDictionary<string, object> ExtraInfo = new Dictionary<string, object>(); public Dictionary<string, object> ExtraInfo = new Dictionary<string, object>();
public List<Language> Languages = new List<Language>(); public List<Language> Languages = new List<Language>();
public string ReleaseGroup { get; set; } public string ReleaseGroup { get; set; }
public string ReleaseHash { get; set; } public string ReleaseHash { get; set; }

@ -5,12 +5,10 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Mono.Disk namespace NzbDrone.Mono.Disk
{ {
// this is here to resolve ambiguity in GetValueOrDefault extension method in net core 3
using NzbDrone.Common.Extensions;
public interface IProcMountProvider public interface IProcMountProvider
{ {
List<IMount> GetMounts(); List<IMount> GetMounts();

@ -6,7 +6,6 @@ using Nancy;
using Nancy.Bootstrapper; using Nancy.Bootstrapper;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace Radarr.Http.Extensions.Pipelines namespace Radarr.Http.Extensions.Pipelines
{ {
@ -81,7 +80,7 @@ namespace Radarr.Http.Extensions.Pipelines
private static bool ContentLengthIsTooSmall(Response response) private static bool ContentLengthIsTooSmall(Response response)
{ {
var contentLength = response.Headers.GetValueOrDefault("Content-Length"); var contentLength = response.Headers.TryGetValue("Content-Length", out var value) ? value : null;
if (contentLength != null && long.Parse(contentLength) < 1024) if (contentLength != null && long.Parse(contentLength) < 1024)
{ {
@ -93,7 +92,7 @@ namespace Radarr.Http.Extensions.Pipelines
private static bool AlreadyGzipEncoded(Response response) private static bool AlreadyGzipEncoded(Response response)
{ {
var contentEncoding = response.Headers.GetValueOrDefault("Content-Encoding"); var contentEncoding = response.Headers.TryGetValue("Content-Encoding", out var value) ? value : null;
if (contentEncoding == "gzip") if (contentEncoding == "gzip")
{ {

Loading…
Cancel
Save