Skip to content

Extended Functions

Jani Giannoudis edited this page Jul 25, 2023 · 10 revisions

Extended Functions

For the development of extensive and complex regulations, there is the possibility of extending the runtime functions of the engine with own C# classes. The outsourcing of functions offers various advantages:

  • Code can be reused by higher-level regulations
  • Development in professional development environments (syntax highlighting, Intellisense etc.)
  • Debug support for case and report scripts
  • Better integration in version management systems

The implementation takes place in three steps

  1. implementation of the business functions in C#
  2. register function extension
  3. use the extended functionality

Composite Function

The Bussines functions will be C# classes, which will get access to the WageTypeValueFunction via 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 with wage type value function argument
  • 11-14: Custom wage type value method GetSlalary()

Function Registration

In the next step, the WageTypeValueFunction is extended with partial and access to the previously set type is guaranteed.

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 partial function
  • 5-6: Provide access to the composite function with 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 6 contains the call to the additional wage type function MyRegulation.GetSalary().

The extension can be checked with the Payroll Console

PayrollConsole PayrunEmployeeTest Test.et.json

Next steps

  • Resources with documents, blogs, tests and examples