Pitel
09/24/2021, 11:32 AMval MessageTemplateTextDtoCreateInput.gql
get() = buildString {
append('{')
appendKV("body", body)
appendKV("languageId", languageId)
appendKV("subject", subject, true)
append('}')
}
fun StringBuilder.appendKV(key: CharSequence, value: Any?, last: Boolean = false) {
append(key)
append(':')
if (value is String) {
append('"')
}
append(
when (value) {
is Array<*> -> value.joinToString(",", "[", "]") {
it.asDynamic().gql as? CharSequence ?: "" // !!! PROBLEM HERE !!!
}
else -> value
}
)
if (value is String) {
append('"')
}
if (!last) {
append(',')
}
}
The problem is, how can I dynamicaly get the .gql
extension value I created?
• I understand, that Kotlin can't know from Array<*>
that the members has the .gql
extension.
• I know I can't use rflection in JS to look if the extension is there.
• Sealed classes/interfaces might be the solutionm, but I can't change the DTOs.
• asDynamic().gql
does not work (this is a bit WTF to me, I thought this might work and at worst throw an exception or something.)
So, any idea how to do this?turansky
09/24/2021, 12:04 PMit.unsafeCast<MessageTemplateTextDtoCreateInput>().gql
turansky
09/24/2021, 12:06 PMMessageTemplateTextDtoCreateInput
is class:
(it as MessageTemplateTextDtoCreateInput).gcl
Pitel
09/24/2021, 12:35 PMMessageTemplateTextDtoCreateInput
.
So, the simpliest solution I come up with is simple when
and is
checks for each class with .gql
extension.