shaun-wild / KProxy

A lightweight Kotlin wrapper of the Proxy API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KProxy

A lightweight Kotlin wrapper of the Proxy API.

CI


Installation

Add jitpack to your repositories.

repositories {
    maven("https://jitpack.io")
}

Add the dependency:

implementation("com.github.shaun-wild:KProxy:[version]")

Usage

Declare your interface:

interface MyInterface {
    val foo: String
}

Create your KInvocationHandler:

object MyInvocationHandler : KInvocationHandler {
    override fun invokeKPropertyRead(proxy: Any?, kProperty: KProperty<*>): Any? {
        TODO("Not yet implemented")
    }

    override fun invokeKPropertyWrite(proxy: Any?, kMutableProperty: KMutableProperty<*>, value: Any?) {
        TODO("Not yet implemented")
    }

    override fun invokeKFunction(proxy: Any?, kFunction: KFunction<*>, args: Array<Any?>): Any? {
        TODO("Not yet implemented")
    }
}

Create the proxy:

val myProxy = KProxy.newProxyInstance<MyInterface>(MyInvocationHandler)

Now you can use your returned object and the proxy implementation will be used:

println(myProxy.foo)

This project uses Kotlin version 1.6.10

License

MIT - Give me a shout-out if you like this! 🚀

About

A lightweight Kotlin wrapper of the Proxy API.

License:MIT License


Languages

Language:Kotlin 100.0%