Skip to content

Commit

Permalink
fix: Enum extension method is now a plain static method
Browse files Browse the repository at this point in the history
  • Loading branch information
pkeefe committed Oct 11, 2018
1 parent 3191aa8 commit cb9ed66
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions library/src/main/java/com/perculacreative/ktx/Enum.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.perculacreative.ktx

inline fun <reified T : Enum<T>> Enum<T>.safeValueOf(name: String): T? {
/**
* Returns an enum entry with specified name.
*/
inline fun <reified T : Enum<T>> enumSafeValueOf(name: String): T? {
return try {
enumValueOf<T>(name)
} catch (e: IllegalArgumentException) {
} catch (e: Exception) {
null
}
}
}

0 comments on commit cb9ed66

Please sign in to comment.