25 lines
775 B
C#
25 lines
775 B
C#
|
|
using System.Text.Json;
|
||
|
|
using System.Text.Json.Serialization;
|
||
|
|
|
||
|
|
namespace IdentityShroud.Core.Model;
|
||
|
|
|
||
|
|
[JsonConverter(typeof(RealmSigningKeyIdJsonConverter))]
|
||
|
|
public readonly record struct RealmSigningKeyId(Guid Id)
|
||
|
|
{
|
||
|
|
public override string ToString() => Id.ToString("N");
|
||
|
|
|
||
|
|
public static RealmSigningKeyId NewId()
|
||
|
|
{
|
||
|
|
return new(Guid.NewGuid());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class RealmSigningKeyIdJsonConverter : JsonConverter<RealmSigningKeyId>
|
||
|
|
{
|
||
|
|
public override RealmSigningKeyId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||
|
|
=> new (reader.GetGuid());
|
||
|
|
|
||
|
|
public override void Write(Utf8JsonWriter writer, RealmSigningKeyId value, JsonSerializerOptions options)
|
||
|
|
=> writer.WriteStringValue(value.ToString());
|
||
|
|
}
|