private static EventBase TranslateJson(string json) { var jsonDocument = JsonDocument.Parse(json); var type = EventBase.EventTypeEnumToType( (EventType)jsonDocument.RootElement .EnumerateObject() .First(x => x.NameEquals(nameof(EventBase.Type))) .Value.GetInt32()); return((EventBase)JsonSerializer.Deserialize(json, type)); }