From eff187f0640d41310ad13f91bd4ee9e6cac0f833 Mon Sep 17 00:00:00 2001 From: uwaa Date: Sat, 4 Jan 2025 14:54:45 +0000 Subject: [PATCH] pleroma: nullable implicit conversions --- Pleroma/Models/Account.cs | 4 ++++ Pleroma/Models/Status.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Pleroma/Models/Account.cs b/Pleroma/Models/Account.cs index 4689ccc..8ce75d4 100644 --- a/Pleroma/Models/Account.cs +++ b/Pleroma/Models/Account.cs @@ -71,7 +71,11 @@ public readonly struct AccountID(string id) { public static implicit operator AccountID(string id) => new AccountID(id); + public static implicit operator AccountID?(string? id) => id == null ? new AccountID?() : new AccountID(id); + public static implicit operator AccountID(Account account) => new AccountID(account.ID); + + public static implicit operator AccountID?(Account? account) => account == null ? new AccountID?() : new AccountID(account.ID); public static implicit operator AccountID(Relationship relationship) => new AccountID(relationship.ID); diff --git a/Pleroma/Models/Status.cs b/Pleroma/Models/Status.cs index 90f9883..d0c61f1 100644 --- a/Pleroma/Models/Status.cs +++ b/Pleroma/Models/Status.cs @@ -222,8 +222,12 @@ public readonly struct StatusID(string id) : IEquatable { public static implicit operator StatusID(string id) => new StatusID(id); + public static implicit operator StatusID?(string? id) => id == null ? new StatusID?() : new StatusID(id); + public static implicit operator StatusID(Status status) => new StatusID(status.ID); + public static implicit operator StatusID?(Status? status) => status == null ? new StatusID?() : new StatusID(status.ID); + public readonly string ID = id; public override string ToString() => ID;