I used the Code (Script) Component for some minor things and then got to a feature that would be easily solved with a recursive function but hard to solve within only one function.
So I create a simple script with only a return statement (return intext;) and clicked the "View Source Code" button in the "4. Test Page" in the wizard and got something like this:
using System;
namespace DynamicNamespace {
public class DynamicClass {
public System.String DynamicMethod(System.String intext)
{
return intext;
}
Then I realized that I could perhaps "inject" the function that I needed and tested with the code below to see if there where any validator that would stop me from doing this.
(If you look closely to the code I added an "}" after my function call and then declared my function but excluded the "}" from the end of the function.)
return myFunction(intext);
}
private String myFunction(String intext)
{
char[] charArray = intext.ToCharArray();
Array.Reverse( charArray );
return new string( charArray );
When I clicked "View Source Code" button in the "4. Test Page" in the wizard and got something like this:
using System;
namespace DynamicNamespace {
public class DynamicClass {
public System.String DynamicMethod(System.String intext)
{
return myFunction(intext);
}
private String myFunction(String intext)
{
char[] charArray = intext.ToCharArray();
Array.Reverse( charArray );
return new string( charArray );
}
}
}
as you can see the end result is valid code and it will compile and return a reversed version of the intext string.
Using this "hack" you can write much more complex code with functions and will be able to write code with recursive functions and convenient functions to make your code more manageable.
I have included a small workflow with the code in the example.
Happy coding and I hope you can make use of my little finding.