mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 16:26:12 +00:00
fix not reading enum values correctly
This commit is contained in:
parent
58b1bd115f
commit
a5bca0a9bb
@ -11,6 +11,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
//TODO improve this
|
||||||
public class OldEnum {
|
public class OldEnum {
|
||||||
|
|
||||||
private static final Class<?> oldEnum;
|
private static final Class<?> oldEnum;
|
||||||
@ -25,11 +26,16 @@ public class OldEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T valueOf(Class<? extends T> c, String name) {
|
public static <T> T valueOf(Class<? extends T> c, String name) {
|
||||||
try {
|
return valueOf(c, name, name.replace(".", "_"));
|
||||||
return (T) c.getDeclaredField(name).get(null);
|
}
|
||||||
} catch (Throwable e) {
|
|
||||||
return null;
|
public static <T> T valueOf(Class<? extends T> c, String... names) {
|
||||||
|
for (final String name : names) {
|
||||||
|
try {
|
||||||
|
return (T) c.getDeclaredField(name).get(null);
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String name(Object o) {
|
public static String name(Object o) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user