From 3ed00f732a284b5a3e96e52d4e3a71869135869b Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 26 Jun 2023 02:43:54 +0200 Subject: Dependency injection stuff --- .../Extensions/IEnumerableExtensions.cs | 31 ++-------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'MatrixRoomUtils.Core/Extensions/IEnumerableExtensions.cs') diff --git a/MatrixRoomUtils.Core/Extensions/IEnumerableExtensions.cs b/MatrixRoomUtils.Core/Extensions/IEnumerableExtensions.cs index 98b0aab..8994529 100644 --- a/MatrixRoomUtils.Core/Extensions/IEnumerableExtensions.cs +++ b/MatrixRoomUtils.Core/Extensions/IEnumerableExtensions.cs @@ -1,36 +1,9 @@ -using System.Reflection; -using System.Text.Json; using MatrixRoomUtils.Core.Interfaces; -using MatrixRoomUtils.Core.Responses; namespace MatrixRoomUtils.Core.Extensions; -public static class IEnumerableExtensions { - public static List DeserializeMatrixTypes(this List stateEvents) { - return stateEvents.Select(DeserializeMatrixType).ToList(); - } - - public static StateEventResponse DeserializeMatrixType(this JsonElement stateEvent) { - var type = stateEvent.GetProperty("type").GetString(); - var knownType = StateEvent.KnownStateEventTypes.FirstOrDefault(x => x.GetCustomAttribute()?.EventName == type); - if (knownType == null) { - Console.WriteLine($"Warning: unknown event type '{type}'!"); - return new StateEventResponse(); - } - - var eventInstance = Activator.CreateInstance(typeof(StateEventResponse).MakeGenericType(knownType))!; - stateEvent.Deserialize(eventInstance.GetType()); - - return (StateEventResponse) eventInstance; - } - - public static void Replace(this List stateEvents, StateEvent old, StateEvent @new) { - var index = stateEvents.IndexOf(old); - if (index == -1) return; - stateEvents[index] = @new; - } -} - +[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class MatrixEventAttribute : Attribute { public string EventName { get; set; } + public bool Legacy { get; set; } } \ No newline at end of file -- cgit 1.5.1