// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.ComponentModel; using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; using EpicGames.Core; namespace EpicGames.Horde.Acls { /// /// Wraps a string used to describe an ACL action /// /// Name of the action [JsonSchemaString] [JsonConverter(typeof(AclActionJsonConverter))] [TypeConverter(typeof(AclActionTypeConverter))] public readonly record struct AclAction(string Name) { /// public override string ToString() => Name; } /// /// Type converter for NamespaceId to and from JSON /// sealed class AclActionJsonConverter : JsonConverter { /// public override AclAction Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => new AclAction(reader.GetString()!); /// public override void Write(Utf8JsonWriter writer, AclAction value, JsonSerializerOptions options) => writer.WriteStringValue(value.Name); } /// /// Type converter from strings to NamespaceId objects /// sealed class AclActionTypeConverter : TypeConverter { /// public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) => sourceType == typeof(string); /// public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) => new AclAction((string)value); } }