Using Custom Methods
In addition to the Execute()
method, you can also define your own custom methods within the CPHInline
class.
Adding Custom Methods
To add a custom method, simply define a new method within your CPHInline
class.
You can call your custom method from within the Execute()
method or from any other methods in the same class. This includes Lifecycle Methods, or even other custom methods you have defined.
public bool Execute()
{
CustomMethod(); // Call your custom method
int sum = Add(5, 10); // Call another custom method that takes parameters
return true;
}
public void CustomMethod()
{
CPH.LogInfo("This is a custom method!"); // You can even use CPH methods here!
}
public int Add(int a, int b)
{
return a + b; // This method takes two integers and returns their sum
}
This allows you to organize your code better, especially if you have repetitive tasks or complex logic that you want to encapsulate in separate methods.
Sharing Methods Between Actions
To do this, your method must be declared as outlined below:
- Visibility must be
public
- Method must not take any parameters
- Return type must be
bool
- Return
true
to indicate success - Return
false
to indicate failure and stop executeion of further sub-actions
- Return
public bool CustomMethod()
{
CPH.LogInfo("This is a custom method that can be called from other actions!");
return true; // Return true to indicate success
}
Name
in your Execute C# Code sub-action settings for it to be discoverable by other actions.Execute Method Sub-Action
To call your custom method from another action, you can use the Execute C# Method sub-action.
C# ExecuteMethod
You can also call your custom method directly from another C# code action using the ExecuteMethod()
method of the CPH
class.
public bool Execute()
{
CPH.ExecuteMethod("YourActionName", "CustomMethod"); return true;
}
YourActionName
with the Name
defined in your Execute C# Code sub-action settings and CustomMethod
with the name of your C# method.