elect
06/15/2022, 10:57 AMfun TfFile.cert_request(configure: CertRequest.() -> Unit): CertRequest
fun TfFile.cert_request(configure: CertRequest.() -> Unit): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CertRequest>>
@JvmName works only for case like List<String and List<Int and @OverloadResolutionByLambdaReturnType only with lambdas returning different valuesJoffrey
06/15/2022, 11:04 AMelect
06/15/2022, 11:20 AMcert_request { }
val a by cert_request { }
if I make use of delegation or notJoffrey
06/15/2022, 11:25 AMby, how do you know which one it is?elect
06/15/2022, 11:33 AMYoussef Shoaib [MOD]
06/15/2022, 2:47 PMoperator fun CertRequest.provideDelegate
? Could that do the trick?elect
06/15/2022, 2:50 PMprovideDelegate, but I didn't have any luck 😕Youssef Shoaib [MOD]
06/15/2022, 2:52 PMCertRequest the `provideDelegate`method should be called automatically, allowing you to do whatever you want. In fact, you can take the current method which returns a Delegate provider and instead make it return its delegate in CertRequest.provideDelegateYoussef Shoaib [MOD]
06/15/2022, 2:52 PMTfFile a context receiver I guess, but it should work I believe.elect
06/15/2022, 2:57 PMCertRequest.provideDelegate? I need as owner TfFile (I have to add this CertRequest instance to a list inside TfFile)Youssef Shoaib [MOD]
06/15/2022, 2:59 PMelect
06/15/2022, 3:02 PMYoussef Shoaib [MOD]
06/15/2022, 3:03 PMcontext(TfFile)
operator fun CertRequest.provideDelegate(...): ReadOnlyProperty<...> {
this@TfFile.removeCert(this)
this@TfFile.addCert(generateNewCert())
return ReadOnlyProperty<...> {...}
}Youssef Shoaib [MOD]
06/15/2022, 3:04 PMoperator fun CertRequest.getValue(...): CertRequest = this
In other words, CertRequest is used as a delegate that just returns itself!
That then allows you to have only one TfFile.cert_request and still have it be used as a delegate when neededelect
06/15/2022, 3:13 PMval a by cert_request , in this case a and save it inside CertRequestelect
06/15/2022, 3:22 PMprovideDelegate patternYoussef Shoaib [MOD]
06/15/2022, 3:35 PMoperator fun CertRequest.provideDelegate(...): CertRequest= this.apply {
this.myName = property.name
}
operator fun CertRequest.getValue(...): CertRequest = thiselect
06/15/2022, 3:37 PMYoussef Shoaib [MOD]
06/15/2022, 3:43 PMcontext(TfFile)
operator fun CertRequest.provideDelegate(...): CertRequest = this.copy(name = property.name).also {
this@TfFile.removeCertificate(this)
this@TfFile.addCertificate(it)
}
operator fun CertRequest.getValue(...): CertRequest = this
But yes I'd suggest to just make it modifiable to make it easierelect
06/15/2022, 4:04 PMby cert_request is supposed to call CertRequest.provideDelegate? Because it's always being redirected to TfFile.cert_requestelect
06/15/2022, 4:07 PMval a by CertRequest()?
It works quite good in this way indeedYoussef Shoaib [MOD]
06/15/2022, 4:10 PMelect
06/15/2022, 4:11 PMelect
06/15/2022, 4:12 PMTfFile.cert_request is called, and then CertRequest.provideDelegateelect
06/15/2022, 4:14 PMYoussef Shoaib [MOD]
06/15/2022, 4:14 PM