aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Extensions')
-rw-r--r--MediaBrowser.Common/Extensions/BaseExtensions.cs2
-rw-r--r--MediaBrowser.Common/Extensions/CopyToExtensions.cs28
-rw-r--r--MediaBrowser.Common/Extensions/HttpContextExtensions.cs2
-rw-r--r--MediaBrowser.Common/Extensions/MethodNotAllowedException.cs2
-rw-r--r--MediaBrowser.Common/Extensions/ProcessExtensions.cs4
-rw-r--r--MediaBrowser.Common/Extensions/RateLimitExceededException.cs1
-rw-r--r--MediaBrowser.Common/Extensions/ResourceNotFoundException.cs2
-rw-r--r--MediaBrowser.Common/Extensions/ShuffleExtensions.cs43
-rw-r--r--MediaBrowser.Common/Extensions/StreamExtensions.cs51
9 files changed, 2 insertions, 133 deletions
diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs
index 40020093b..08964420e 100644
--- a/MediaBrowser.Common/Extensions/BaseExtensions.cs
+++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
using System.Security.Cryptography;
using System.Text;
diff --git a/MediaBrowser.Common/Extensions/CopyToExtensions.cs b/MediaBrowser.Common/Extensions/CopyToExtensions.cs
deleted file mode 100644
index 94bf7c740..000000000
--- a/MediaBrowser.Common/Extensions/CopyToExtensions.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-#nullable enable
-
-using System.Collections.Generic;
-
-namespace MediaBrowser.Common.Extensions
-{
- /// <summary>
- /// Provides <c>CopyTo</c> extensions methods for <see cref="IReadOnlyList{T}" />.
- /// </summary>
- public static class CopyToExtensions
- {
- /// <summary>
- /// Copies all the elements of the current collection to the specified list
- /// starting at the specified destination array index. The index is specified as a 32-bit integer.
- /// </summary>
- /// <param name="source">The current collection that is the source of the elements.</param>
- /// <param name="destination">The list that is the destination of the elements copied from the current collection.</param>
- /// <param name="index">A 32-bit integer that represents the index in <c>destination</c> at which copying begins.</param>
- /// <typeparam name="T">The type of the array.</typeparam>
- public static void CopyTo<T>(this IReadOnlyList<T> source, IList<T> destination, int index = 0)
- {
- for (int i = 0; i < source.Count; i++)
- {
- destination[index + i] = source[i];
- }
- }
- }
-}
diff --git a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
index e51ad42d1..1e5877c84 100644
--- a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
+++ b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
@@ -17,7 +17,7 @@ namespace MediaBrowser.Common.Extensions
{
return (context.Connection.LocalIpAddress == null
&& context.Connection.RemoteIpAddress == null)
- || context.Connection.LocalIpAddress.Equals(context.Connection.RemoteIpAddress);
+ || Equals(context.Connection.LocalIpAddress, context.Connection.RemoteIpAddress);
}
/// <summary>
diff --git a/MediaBrowser.Common/Extensions/MethodNotAllowedException.cs b/MediaBrowser.Common/Extensions/MethodNotAllowedException.cs
index 258bd6662..48e758ee4 100644
--- a/MediaBrowser.Common/Extensions/MethodNotAllowedException.cs
+++ b/MediaBrowser.Common/Extensions/MethodNotAllowedException.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
namespace MediaBrowser.Common.Extensions
diff --git a/MediaBrowser.Common/Extensions/ProcessExtensions.cs b/MediaBrowser.Common/Extensions/ProcessExtensions.cs
index 2f52ba196..08e01bfd6 100644
--- a/MediaBrowser.Common/Extensions/ProcessExtensions.cs
+++ b/MediaBrowser.Common/Extensions/ProcessExtensions.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
using System.Diagnostics;
using System.Threading;
@@ -42,7 +40,7 @@ namespace MediaBrowser.Common.Extensions
// Add an event handler for the process exit event
var tcs = new TaskCompletionSource<bool>();
- process.Exited += (sender, args) => tcs.TrySetResult(true);
+ process.Exited += (_, _) => tcs.TrySetResult(true);
// Return immediately if the process has already exited
if (process.HasExitedSafe())
diff --git a/MediaBrowser.Common/Extensions/RateLimitExceededException.cs b/MediaBrowser.Common/Extensions/RateLimitExceededException.cs
index 7c7bdaa92..95802a462 100644
--- a/MediaBrowser.Common/Extensions/RateLimitExceededException.cs
+++ b/MediaBrowser.Common/Extensions/RateLimitExceededException.cs
@@ -1,4 +1,3 @@
-#nullable enable
#pragma warning disable CS1591
using System;
diff --git a/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs b/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs
index ebac9d8e6..22130c5a1 100644
--- a/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs
+++ b/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs
@@ -1,5 +1,3 @@
-#nullable enable
-
using System;
namespace MediaBrowser.Common.Extensions
diff --git a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
deleted file mode 100644
index 6f0ea9bd5..000000000
--- a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-#nullable enable
-
-using System;
-using System.Collections.Generic;
-
-namespace MediaBrowser.Common.Extensions
-{
- /// <summary>
- /// Provides <c>Shuffle</c> extensions methods for <see cref="IList{T}" />.
- /// </summary>
- public static class ShuffleExtensions
- {
- private static readonly Random _rng = new Random();
-
- /// <summary>
- /// Shuffles the items in a list.
- /// </summary>
- /// <param name="list">The list that should get shuffled.</param>
- /// <typeparam name="T">The type.</typeparam>
- public static void Shuffle<T>(this IList<T> list)
- {
- list.Shuffle(_rng);
- }
-
- /// <summary>
- /// Shuffles the items in a list.
- /// </summary>
- /// <param name="list">The list that should get shuffled.</param>
- /// <param name="rng">The random number generator to use.</param>
- /// <typeparam name="T">The type.</typeparam>
- public static void Shuffle<T>(this IList<T> list, Random rng)
- {
- int n = list.Count;
- while (n > 1)
- {
- int k = rng.Next(n--);
- T value = list[k];
- list[k] = list[n];
- list[n] = value;
- }
- }
- }
-}
diff --git a/MediaBrowser.Common/Extensions/StreamExtensions.cs b/MediaBrowser.Common/Extensions/StreamExtensions.cs
deleted file mode 100644
index cd77be7b2..000000000
--- a/MediaBrowser.Common/Extensions/StreamExtensions.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-#nullable enable
-
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace MediaBrowser.Common.Extensions
-{
- /// <summary>
- /// Class BaseExtensions.
- /// </summary>
- public static class StreamExtensions
- {
- /// <summary>
- /// Reads all lines in the <see cref="Stream" />.
- /// </summary>
- /// <param name="stream">The <see cref="Stream" /> to read from.</param>
- /// <returns>All lines in the stream.</returns>
- public static string[] ReadAllLines(this Stream stream)
- => ReadAllLines(stream, Encoding.UTF8);
-
- /// <summary>
- /// Reads all lines in the <see cref="Stream" />.
- /// </summary>
- /// <param name="stream">The <see cref="Stream" /> to read from.</param>
- /// <param name="encoding">The character encoding to use.</param>
- /// <returns>All lines in the stream.</returns>
- public static string[] ReadAllLines(this Stream stream, Encoding encoding)
- {
- using (StreamReader reader = new StreamReader(stream, encoding))
- {
- return ReadAllLines(reader).ToArray();
- }
- }
-
- /// <summary>
- /// Reads all lines in the <see cref="StreamReader" />.
- /// </summary>
- /// <param name="reader">The <see cref="StreamReader" /> to read from.</param>
- /// <returns>All lines in the stream.</returns>
- public static IEnumerable<string> ReadAllLines(this StreamReader reader)
- {
- string? line;
- while ((line = reader.ReadLine()) != null)
- {
- yield return line;
- }
- }
- }
-}