Skip to content

Commit

Permalink
feat: Match enums with toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
percula committed Sep 17, 2019
1 parent 2a9c829 commit 1acd411
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/src/main/java/dev/percula/ktx/Enum.kt
Original file line number Diff line number Diff line change
@@ -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 <reified T : Enum<T>> enumSafeValueOf(name: String): T? {
return try {
enumValueOf<T>(name)
} catch (e: Exception) {
null
enumValues<T>().firstOrNull { it.toString() == name }
}
}

0 comments on commit 1acd411

Please sign in to comment.