aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'src/Jellyfin.Extensions')
-rw-r--r--src/Jellyfin.Extensions/GuidExtensions.cs26
-rw-r--r--src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs2
2 files changed, 27 insertions, 1 deletions
diff --git a/src/Jellyfin.Extensions/GuidExtensions.cs b/src/Jellyfin.Extensions/GuidExtensions.cs
new file mode 100644
index 000000000..95c591a82
--- /dev/null
+++ b/src/Jellyfin.Extensions/GuidExtensions.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Jellyfin.Extensions;
+
+/// <summary>
+/// Guid specific extensions.
+/// </summary>
+public static class GuidExtensions
+{
+ /// <summary>
+ /// Determine whether the guid is default.
+ /// </summary>
+ /// <param name="guid">The guid.</param>
+ /// <returns>Whether the guid is the default value.</returns>
+ public static bool IsEmpty(this Guid guid)
+ => guid.Equals(default);
+
+ /// <summary>
+ /// Determine whether the guid is null or default.
+ /// </summary>
+ /// <param name="guid">The guid.</param>
+ /// <returns>Whether the guid is null or the default valueF.</returns>
+ public static bool IsNullOrEmpty([NotNullWhen(false)] this Guid? guid)
+ => guid is null || guid.Value.IsEmpty();
+}
diff --git a/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs b/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs
index 656e3c3da..0a50b5c3b 100644
--- a/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs
+++ b/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs
@@ -18,7 +18,7 @@ namespace Jellyfin.Extensions.Json.Converters
{
// null got handled higher up the call stack
var val = value!.Value;
- if (val.Equals(default))
+ if (val.IsEmpty())
{
writer.WriteNullValue();
}