From 1acd4119a7aaf84c5cf628e95ef98783278b5396 Mon Sep 17 00:00:00 2001 From: Peter Keefe <16809252+percula@users.noreply.github.com> Date: Tue, 17 Sep 2019 14:34:43 -0400 Subject: [PATCH] feat: Match enums with toString() --- library/src/main/java/dev/percula/ktx/Enum.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/dev/percula/ktx/Enum.kt b/library/src/main/java/dev/percula/ktx/Enum.kt index 21d8022..01505ed 100644 --- a/library/src/main/java/dev/percula/ktx/Enum.kt +++ b/library/src/main/java/dev/percula/ktx/Enum.kt @@ -1,12 +1,12 @@ package dev.percula.ktx /** - * Returns an enum entry with specified name. + * Returns an enum entry with specified name. If the enum has overriden toString(), it will use that */ inline fun > enumSafeValueOf(name: String): T? { return try { enumValueOf(name) } catch (e: Exception) { - null + enumValues().firstOrNull { it.toString() == name } } } \ No newline at end of file