-
-
Notifications
You must be signed in to change notification settings - Fork 19
ExtendedFunctions
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:
- Implement the business functions in C#
- Register the function extension
- Use the extended functionality
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 methodGetSalary()
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 usingpartial -
5-6: Expose access to the composite function via the propertyMyRegulation
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
- Resources with documents, blogs, tests and examples
🤝 Thank you for supporting this project with a donation.
⚡ This is a pre-relase version of the initial development, please read the restrictions.
- Payroll Engine