Extending method keywords
Hi community!
Is there any way to create new method keywords?
For example:
ClassMethod TestOne() [ MyKeyword = MyValue ] { // Implementation }
Another doubt (maybe another topic)
How can I generate new methods at compilation time for the same class?
I tried method generators, but It only gets compiled when I compile for the second time.
I also read this comment but I could not find out how to generate the methods and get them compiled in the first compilation.
For example:
Class util.Test { ClassMethod TestOne() { Write 1 } ClassMethod TestTwo() { Write 1 } }
Expected:
Class util.Test { ClassMethod TestOne() { Write 1 } ClassMethod TestTwo() { Write 1 } ClassMethod TestOneDoSomethingElse() { // My implementation } ClassMethod TestTwoDoSomethingElse() { // My implementation } }
Thank you all
Please show a sample. Compiling a class with method generators should work on a first compilation.
When I compile the code, It generates correctly.
but if you see the source, It is not compiled
When I compile for the second time:
Thank you Timothy!
It worked perfectly
They are executed after the compiler loads the definitions.
Any changes we do in class definitions is not going to be caught by the compiler since it has already built the dependencies/inheritances.
I.e. you need Callback methods for Studio, Atelier, etc.?
It would be really nice.
This is not the first time I needed something to be triggered before the compilation...
This not it?
What flags are you compiling with? For me it works on a first compilation:
As you see from the log both classes don't exist, but after one compilation I can call TestOneDoSomethingElse method and it works. What's your output for:
I did exactly as you!
When you first imported the class, did you compile it?
If so, maybe Caché had already written the new methods and when you compiled throught terminal It worked.
Try to remove the methods " TestOneDoSomethingElse" and " TestTwoDoSomethingElse" and compile the class again. Check it out if it generates the source correctly
My bad, I've done the UnCompile but forgot to remove already generated methods.
Unrelated but it's better to return a status from a generator method:
Re: extending method keywords, you can't do that at this time, but a useful approximation is structuring a comment - for example:
And then looking at the %Dictionary.MethodDefinition / %Dictionary.CompiledMethod documentation in a generator method. (But it looks like you might already be on to that with @AutoGenerated.)
Re: making first compilation work, this works for me, by making the first compilation automatically trigger a second one when needed:
Test code:
What you probably need is some kind of OnCompile callback in which you would be able to change the actual class definition based on meta data.
Adding methods and properties.
This is something I've asking for since the incarnation of Cache in 1997.