about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-10-23 16:12:27 +0200
committerRory& <root@rory.gay>2024-10-23 16:12:27 +0200
commitbf1664b254bfc224f0087eb82fdba5235fbd162e (patch)
tree0545bcf3ed973fa38216f0c59d900095316082b3
parentMinor cleanups, support for loading access tokens from disk or appservice (diff)
downloadLibMatrix-bf1664b254bfc224f0087eb82fdba5235fbd162e.tar.xz
Add helper function to turn event type -> types github/master
-rw-r--r--LibMatrix.EventTypes/EventContent.cs12
1 files changed, 11 insertions, 1 deletions
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<string> GetMatchingEventTypes<T>() where T : EventContent {
+        var type = typeof(T);
+        var eventTypes = new List<string>();
+        foreach (var attr in type.GetCustomAttributes<MatrixEventAttribute>(true)) {
+            eventTypes.Add(attr.EventName);
+        }
+        return eventTypes;
+    }
+}
 
 public class UnknownEventContent : TimelineEventContent;