Skip to content

Commit

Permalink
feat: Add Enum.safeValueOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
pkeefe committed Oct 1, 2018
1 parent cf87d47 commit 0bbf3aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 15
targetSdkVersion 28
versionCode 2
versionName "1.0-alpha04"
versionName "1.0-alpha05"
}

buildTypes {
Expand Down
9 changes: 9 additions & 0 deletions library/src/main/java/com/perculacreative/ktx/Enum.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.perculacreative.ktx

inline fun <reified T : Enum<T>> Enum<T>.safeValueOf(name: String): T? {
return try {
enumValueOf<T>(name)
} catch (e: IllegalArgumentException) {
null
}
}

0 comments on commit 0bbf3aa

Please sign in to comment.