about summary refs log tree commit diff
path: root/LibMatrix/StateEvent.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-05-20 06:58:46 +0200
committerRory& <root@rory.gay>2024-05-20 06:58:46 +0200
commit33ad8793abec263eccfa29cb51e23e4dcfc246ab (patch)
treee1a70f2f145f0827501e1ad26971fa0bf51e8945 /LibMatrix/StateEvent.cs
parentLog unrecognised types (diff)
downloadLibMatrix-33ad8793abec263eccfa29cb51e23e4dcfc246ab.tar.xz
Log warning if registering a duplicate type
Diffstat (limited to '')
-rw-r--r--LibMatrix/StateEvent.cs6
1 files changed, 5 insertions, 1 deletions
diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs
index e3de7e6..81ee3fe 100644
--- a/LibMatrix/StateEvent.cs
+++ b/LibMatrix/StateEvent.cs
@@ -19,7 +19,11 @@ public class StateEvent {
         new Dictionary<string, Type>(),
         (dict, type) => {
             var attrs = type.GetCustomAttributes<MatrixEventAttribute>();
-            foreach (var attr in attrs) dict[attr.EventName] = type;
+            foreach (var attr in attrs) {
+                if (dict.TryGetValue(attr.EventName, out var existing))
+                    Console.WriteLine($"Duplicate event type '{attr.EventName}' registered for types '{existing.Name}' and '{type.Name}'");
+                dict[attr.EventName] = type;
+            }
 
             return dict;
         }).OrderBy(x => x.Key).ToFrozenDictionary();