Added new function to call CurrentClass in ReflectionFactory

This commit is contained in:
2022-08-10 00:19:04 +08:00
parent b92c390ae9
commit b9f41a690c
3 changed files with 65 additions and 0 deletions

View File

@@ -147,10 +147,20 @@ inline fun Class<*>.constructor(initiate: ConstructorFinder.() -> Unit = { empty
* @return [T]
*/
inline fun <reified T : Any> T.current(initiate: CurrentClass.() -> Unit): T {
if (javaClass.name == CurrentClass::class.java.name) error("Cannot create itself within CurrentClass itself")
CurrentClass(javaClass, self = this).apply(initiate)
return this
}
/**
* 获得当前实例的类操作对象
* @return [CurrentClass]
*/
inline fun <reified T : Any> T.current(): CurrentClass {
if (javaClass.name == CurrentClass::class.java.name) error("Cannot create itself within CurrentClass itself")
return CurrentClass(javaClass, self = this)
}
/**
* 通过构造方法创建新实例 - 任意类型 [Any]
* @param param 方法参数