diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-02-09 16:32:46 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-02-09 16:32:46 +0100 |
commit | 4ef9ae4b396b0eb37036d4008e8cb40e468dbe73 (patch) | |
tree | 6bb4d25754fefc52333a5fc44dd721c333314240 /LibMatrix/StateEvent.cs | |
parent | Consistently use EventId for event types (diff) | |
download | LibMatrix-4ef9ae4b396b0eb37036d4008e8cb40e468dbe73.tar.xz |
Apply syntax style to LibMatrix
Diffstat (limited to 'LibMatrix/StateEvent.cs')
-rw-r--r-- | LibMatrix/StateEvent.cs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index d78939e..019c428 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -15,14 +15,12 @@ namespace LibMatrix; public class StateEvent { public static FrozenSet<Type> KnownStateEventTypes { get; } = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies().ToFrozenSet(); - + public static FrozenDictionary<string, Type> KnownStateEventTypesByName { get; } = KnownStateEventTypes.Aggregate( 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) dict[attr.EventName] = type; return dict; }).ToFrozenDictionary(); @@ -48,7 +46,7 @@ public class StateEvent { new JsonDecimalStringConverter() } }; - + [JsonIgnore] [SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")] public EventContent? TypedContent { @@ -57,7 +55,7 @@ public class StateEvent { // return null; // } try { - var c= (EventContent)RawContent.Deserialize(GetStateEventType(Type), TypedContentSerializerOptions)!; + var c = (EventContent)RawContent.Deserialize(GetStateEventType(Type), TypedContentSerializerOptions)!; return c; } catch (JsonException e) { @@ -68,9 +66,8 @@ public class StateEvent { return null; } set { - if (value is null) { + if (value is null) RawContent?.Clear(); - } else RawContent = JsonSerializer.Deserialize<JsonObject>(JsonSerializer.Serialize(value, value.GetType())); } } |