From 0bbf3aa81d8554b64b4a038915cd57f13ff00702 Mon Sep 17 00:00:00 2001 From: pkeefe Date: Mon, 1 Oct 2018 10:32:02 -0400 Subject: [PATCH] feat: Add Enum.safeValueOf() --- library/build.gradle | 2 +- library/src/main/java/com/perculacreative/ktx/Enum.kt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/perculacreative/ktx/Enum.kt diff --git a/library/build.gradle b/library/build.gradle index 28915c7..663a1ac 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 15 targetSdkVersion 28 versionCode 2 - versionName "1.0-alpha04" + versionName "1.0-alpha05" } buildTypes { diff --git a/library/src/main/java/com/perculacreative/ktx/Enum.kt b/library/src/main/java/com/perculacreative/ktx/Enum.kt new file mode 100644 index 0000000..7835db7 --- /dev/null +++ b/library/src/main/java/com/perculacreative/ktx/Enum.kt @@ -0,0 +1,9 @@ +package com.perculacreative.ktx + +inline fun > Enum.safeValueOf(name: String): T? { + return try { + enumValueOf(name) + } catch (e: IllegalArgumentException) { + null + } +}