mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
reflection function update
This commit is contained in:
@@ -3,15 +3,15 @@ package net.torvald.reflection
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2023-03-25.
|
* Created by minjaesong on 2023-03-25.
|
||||||
*/
|
*/
|
||||||
fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name
|
inline fun <reified T> Any.extortField(name: String): T? { // yes I'm deliberately using negative words for the function name
|
||||||
return this.javaClass.getDeclaredField(name).let {
|
return this.javaClass.getDeclaredField(name).let {
|
||||||
it.isAccessible = true
|
it.isAccessible = true
|
||||||
it.get(this)
|
it.get(this) as T?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun Any.forceInvoke(name: String, params: Array<Any>): Any? { // yes I'm deliberately using negative words for the function name
|
inline fun <reified T> Any.forceInvoke(name: String, params: Array<Any>): T? { // yes I'm deliberately using negative words for the function name
|
||||||
return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let {
|
return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let {
|
||||||
it.isAccessible = true
|
it.isAccessible = true
|
||||||
it.invoke(this, *params)
|
it.invoke(this, *params) as T?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user