aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2020-11-13 11:24:46 -0700
committercrobibero <cody@robibe.ro>2020-11-13 11:24:46 -0700
commit95ebb9a55ace6c544fa7fa15d0a255a5cee752a8 (patch)
treef5ce2c6ea994d63712d45772ad712ac6bcf79ab6 /Emby.Server.Implementations
parent5f52a58e785fa4ae06fa07a93b81c1e7547ac9f3 (diff)
Use null coalescing when possible
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/AppBase/ConfigurationHelper.cs6
-rw-r--r--Emby.Server.Implementations/Cryptography/CryptographyProvider.cs7
-rw-r--r--Emby.Server.Implementations/Session/WebSocketController.cs7
3 files changed, 3 insertions, 17 deletions
diff --git a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs
index 8cca5cc77..b0a14f43d 100644
--- a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs
+++ b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs
@@ -50,11 +50,7 @@ namespace Emby.Server.Implementations.AppBase
// If the file didn't exist before, or if something has changed, re-save
if (buffer == null || !newBytes.AsSpan(0, newBytesLen).SequenceEqual(buffer))
{
- var directory = Path.GetDirectoryName(path);
- if (directory == null)
- {
- throw new ResourceNotFoundException(nameof(directory));
- }
+ var directory = Path.GetDirectoryName(path) ?? throw new ResourceNotFoundException(nameof(path));
Directory.CreateDirectory(directory);
// Save it after load in case we got new items
diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
index 8d7f73b3c..42db18396 100644
--- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
+++ b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
@@ -81,12 +81,7 @@ namespace Emby.Server.Implementations.Cryptography
throw new CryptographicException($"Requested hash method is not supported: {hashMethod}");
}
- using var h = HashAlgorithm.Create(hashMethod);
- if (h == null)
- {
- throw new ResourceNotFoundException(nameof(h));
- }
-
+ using var h = HashAlgorithm.Create(hashMethod) ?? throw new ResourceNotFoundException(nameof(hashMethod));
if (salt.Length == 0)
{
return h.ComputeHash(bytes);
diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.cs
index 78f83e337..5268ea1b9 100644
--- a/Emby.Server.Implementations/Session/WebSocketController.cs
+++ b/Emby.Server.Implementations/Session/WebSocketController.cs
@@ -58,12 +58,7 @@ namespace Emby.Server.Implementations.Session
private void OnConnectionClosed(object? sender, EventArgs e)
{
- if (sender == null)
- {
- throw new ResourceNotFoundException(nameof(sender));
- }
-
- var connection = (IWebSocketConnection)sender;
+ var connection = sender as IWebSocketConnection ?? throw new ResourceNotFoundException(nameof(sender));
_logger.LogDebug("Removing websocket from session {Session}", _session.Id);
_sockets.Remove(connection);
connection.Closed -= OnConnectionClosed;