Generating Method Arguments with objectgenerator
Hi *,
I want to dynamically generate the arguments of a method during compile time.
'For example, I want the following method
ClassMethod DoCleverStuf() As %Status [ CodeMode = objectgenerator ]
{
do %code.WriteLine(" Set tSC = $$$OK")
...
}to look like this in the .int code.
ClassMethod DoCleverStuf(pValue1 As %Integer, pValue2 As %String) As %Status [ CodeMode = objectgenerator ]
{
// some generated code will be here
}Is this possible? Or alternativel;y, can I generate a whole method at compile time?
Thanks.
Product version: IRIS 2022.3
Discussion (2)2
Comments
Use args... to supply a variable number of parameters:
ClassMethod DoCleverStuf(args...) As %Status [ CodeMode = objectgenerator ]
{
do %code.WriteLine(" For i=1:1:args {")
do %code.WriteLine(" Write args(i)")
do %code.WriteLine(" }")
do %code.WriteLine(" Set tSC = $$$OK")
...
}can I generate a whole method at compile time?
You can use projections to do that. Here's an example.
There are a few more projection examples in isc-rest. Here's my favorite:
https://github.com/intersystems/isc-rest/blob/main/cls/_pkg/isc/rest/mo…
IMO if a user shouldn't modify a method that's automatically generated, it's best to put it in a separate generated class. The above example covers that behavior.