Skip to content

ExtendedFunctions

Jani Giannoudis edited this page Feb 24, 2026 · 1 revision

Extended Functions

For developing extensive and complex regulations, the engine's runtime functions can be extended with custom C# classes. Externalizing functions offers several advantages:

  • Code can be reused by higher-level regulations
  • Development in professional IDEs (syntax highlighting, IntelliSense, etc.)
  • Debug support for case and report scripts
  • Better integration with version control systems

The implementation involves three steps:

  1. Implement the business functions in C#
  2. Register the function extension
  3. Use the extended functionality

Composite Function

The business functions are C# classes that receive the WageTypeValueFunction as a constructor argument:

1  using System;
2  using PayrollEngine.Client.Scripting.Function;
3  namespace ExtendedPayroll.Scripts;
4  public class CompositeWageTypeValueFunction
5  {
6    private WageTypeValueFunction Function { get; }
7    public CompositeWageTypeValueFunction(WageTypeValueFunction function)
8    {
9      Function = function ?? throw new ArgumentNullException(nameof(function));
10   }
11   public decimal GetSalary()
12   {
13     return Function.CaseValue["Salary"];
14   }
15 }

The code in detail:

  • 7-10: Constructor receiving the wage type value function as an argument
  • 11-14: Custom wage type value method GetSalary()

Function Registration

In the next step, WageTypeValueFunction is extended using partial to expose access to the composite type:

1 using ExtendedPayroll.Scripts;
2 namespace PayrollEngine.Client.Scripting.Function;
3 public partial class WageTypeValueFunction
4 {
5   private CompositeWageTypeValueFunction function;
6   public CompositeWageTypeValueFunction MyRegulation => function ??= new(this);
7 }

The code in detail:

  • 3: Extend the function class using partial
  • 5-6: Expose access to the composite function via the property MyRegulation

Extended Function Usage

The extension class can be used in the wage type ValueExpression:

1 "wageTypes": [
2   {
3     "wageTypeNumber": 100,
4     "name": "Salary",
5     "valueExpression": "MyRegulation.GetSalary()"
6   }
7 ]

Line 5 contains the call to the extended wage type function MyRegulation.GetSalary().

The extension can be verified with the Payroll Console:

PayrollConsole PayrunEmployeeTest Test.et.json

Next Steps

  • Resources with documents, blogs, tests and examples

Clone this wiki locally