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

commonMain.hassemble.values.ColorName.kt Maven / Gradle / Ivy

The newest version!
package hassemble.values

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable(ColorName.Companion::class)
data class ColorName(val value: String) {
    override fun toString(): String = value

    companion object : KSerializer {
        override val descriptor: SerialDescriptor =
            PrimitiveSerialDescriptor("ColorName", PrimitiveKind.STRING)
        override fun deserialize(decoder: Decoder) = ColorName(decoder.decodeString())
        override fun serialize(encoder: Encoder, value: ColorName) = encoder.encodeString(value.value)
    }
}

val String.color
    get() = ColorName(this)

val Enum<*>.color
    get() = ColorName(this.name)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy