All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.entity.optional.delegate.OptionalSnowflakeDelegate.kt Maven / Gradle / Ivy

The newest version!
package dev.kord.common.entity.optional.delegate

import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.entity.optional.optionalSnowflake
import dev.kord.common.entity.optional.value
import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty


public fun KMutableProperty0.delegate(): ReadWriteProperty =
    object : ReadWriteProperty {

        override fun getValue(thisRef: Any?, property: KProperty<*>): Snowflake? {
            return [email protected]().value
        }

        override fun setValue(thisRef: Any?, property: KProperty<*>, value: Snowflake?) {
            val optional = if (value == null) OptionalSnowflake.Missing
            else OptionalSnowflake.Value(value.value)
            [email protected](optional)
        }
    }

@JvmName("delegateOptional")
public fun KMutableProperty0.delegate(): ReadWriteProperty =
    object : ReadWriteProperty {

        override fun getValue(thisRef: Any?, property: KProperty<*>): Snowflake? {
            return [email protected]().value
        }

        override fun setValue(thisRef: Any?, property: KProperty<*>, value: Snowflake?) {
            [email protected](value?.optionalSnowflake())
        }

    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy