commonMain.QBittorrentPrefsBody.kt Maven / Gradle / Ivy
package qbittorrent.models
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlin.jvm.JvmName
import kotlin.reflect.KProperty1
class QBittorrentPrefsBuilder {
private val prefs = mutableMapOf()
@Suppress("UNCHECKED_CAST")
fun set(property: KProperty1, value: T?) {
val serialName = QBittorrentPrefsSerialNameMap.map(property.name)
prefs[serialName] = when {
value == null -> JsonNull
else -> Json.encodeToJsonElement(property.getSerializer() as KSerializer, value)
}
}
@JvmName("setInfix")
infix fun KProperty1.set(value: T?) {
set(this, value)
}
fun build(): JsonObject {
return Json.encodeToJsonElement(prefs) as JsonObject
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy