How to call another method in a generated method
I have a class with two methods
Class Foo.Bar
{
ClassMethod Helper()
{
// do something
}
ClassMethod Generated() [ CodeMode = objectgenerator ]
{
do ..Helper()
// do something else
}
}
Since the method Generated is run before the class is compiled, the call to do ..Helper() fails. Is there a way around this other than manual inlining?
Comments
The only way I can think of doing this would be to split out the Helper() ClassMethod into its own class, and then ensure the order of compilation is in such a way that the class containing the Helper class method is compiled. Depending on how you're achieving this, could you use the CompileAfter class keyword?
So something like:
Class 1:
Class Foo.Bar.1
{
ClassMethod Helper()
{
// do something
}
}
Class 2:
Class Foo.Bar.2 [ CompileAfter = (Foo.Bar.1) ]
{
ClassMethod Generated() [ CodeMode = objectgenerator ]
{
do##Class(Foo.Bar.1).Helper()
// do something else
}
}
Only one small addition -- use DependsOn, not CompileAfter. Then ObjectScript compiler makes sure that Foo.Bar.1 is runnable when the Foo.Bar.2 is compiled
https://docs.intersystems.com/iris20241/csp/docbook/Doc.View.cls?KEY=ROBJ_class_dependson
GenerateAfter can help here.
///do ##class(Test.GenerateHelper).Generated()///Hi there!Class Test.GenerateHelper
{
ClassMethod Generated() [ CodeMode = objectgenerator, GenerateAfter = Helper ]
{
set text = ..Helper()
do%code.WriteLine(" write """ _ text _ """")
}
ClassMethod Helper() As%String
{
return"Hi there!"
}
}