From a129b321998614b20e4ebb8a7c1632553ebee981 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Sat, 1 Jun 2024 19:02:28 +0200 Subject: Split event abstractions --- LibMatrix.EventTypes/MatrixEventContent.cs | 60 ------------------------------ 1 file changed, 60 deletions(-) delete mode 100644 LibMatrix.EventTypes/MatrixEventContent.cs (limited to 'LibMatrix.EventTypes/MatrixEventContent.cs') diff --git a/LibMatrix.EventTypes/MatrixEventContent.cs b/LibMatrix.EventTypes/MatrixEventContent.cs deleted file mode 100644 index 81b8c52..0000000 --- a/LibMatrix.EventTypes/MatrixEventContent.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Reflection; -using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; -using ArcaneLibs.Extensions; - -namespace LibMatrix.EventTypes; - -// : MatrixEventContent where T : MatrixEventContent, new() { -/// -/// Extensible Event Content, aims to provide an API similar to JsonNode/JsonObject -/// -/// -/// -[JsonConverter(typeof(MatrixEventContentConverter))] -public class MatrixEventContent { - - [JsonExtensionData, JsonInclude] - public JsonObject InternalJson { get; set; } = new(); - - - - public MatrixEventContent() { } - - public MatrixEventContent(JsonNode json) { - InternalJson = json.AsObject(); - } - - public static implicit operator MatrixEventContent(JsonNode json) => new(json); - - // public static implicit operator JsonNode(MatrixEventContent content) => content.InternalJson; - - [JsonIgnore] - public IEnumerable EventTypes => this.GetType().GetCustomAttributes().Select(x => x.EventType); - - [JsonIgnore] - public string EventType => EventTypes.First(); - - public JsonNode? this[string key] => InternalJson[key]; - - public string ToJson() => InternalJson.ToJson(); - - - public class MatrixEventContentConverter : JsonConverter where T : MatrixEventContent, new() { - public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - // read entire object into a JsonObject - var json = JsonNode.Parse(ref reader); - return new T { InternalJson = json.AsObject() }; - } - - public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) { - value.InternalJson.WriteTo(writer); - } - } -} - -public class MatrixEventAttribute(string eventType, bool deprecated = false) : Attribute { - public string EventType { get; } = eventType; - public bool Deprecated { get; } = deprecated; -} \ No newline at end of file -- cgit 1.4.1