pleroma: nullable implicit conversions

This commit is contained in:
uwaa 2025-01-04 14:54:45 +00:00
parent 6868b6a465
commit eff187f064
2 changed files with 8 additions and 0 deletions

View file

@ -71,8 +71,12 @@ public readonly struct AccountID(string id)
{ {
public static implicit operator AccountID(string id) => new AccountID(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) => 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); public static implicit operator AccountID(Relationship relationship) => new AccountID(relationship.ID);
public readonly string ID = id; public readonly string ID = id;

View file

@ -222,8 +222,12 @@ public readonly struct StatusID(string id) : IEquatable<StatusID>
{ {
public static implicit operator StatusID(string id) => new StatusID(id); 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) => 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 readonly string ID = id;
public override string ToString() => ID; public override string ToString() => ID;