From bf1664b254bfc224f0087eb82fdba5235fbd162e Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 23 Oct 2024 16:12:27 +0200 Subject: Add helper function to turn event type -> types --- LibMatrix.EventTypes/EventContent.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'LibMatrix.EventTypes') diff --git a/LibMatrix.EventTypes/EventContent.cs b/LibMatrix.EventTypes/EventContent.cs index d65a47f..a837252 100644 --- a/LibMatrix.EventTypes/EventContent.cs +++ b/LibMatrix.EventTypes/EventContent.cs @@ -1,10 +1,20 @@ +using System.Reflection; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; namespace LibMatrix.EventTypes; -public abstract class EventContent; +public abstract class EventContent { + public static List GetMatchingEventTypes() where T : EventContent { + var type = typeof(T); + var eventTypes = new List(); + foreach (var attr in type.GetCustomAttributes(true)) { + eventTypes.Add(attr.EventName); + } + return eventTypes; + } +} public class UnknownEventContent : TimelineEventContent; -- cgit 1.5.1