| | | 1 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Models; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Expressions.JavaScript.TypeDefinitions.Builders; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A builder API for building <see cref="FunctionDefinition"/>s. |
| | | 7 | | /// </summary> |
| | | 8 | | public class FunctionDefinitionBuilder |
| | | 9 | | { |
| | 0 | 10 | | private readonly FunctionDefinition _functionDefinition = new(); |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Set the name of the function. |
| | | 14 | | /// </summary> |
| | | 15 | | public FunctionDefinitionBuilder Name(string name) |
| | | 16 | | { |
| | 0 | 17 | | _functionDefinition.Name = name; |
| | 0 | 18 | | return this; |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Set the return type of the function. |
| | | 23 | | /// </summary> |
| | | 24 | | public FunctionDefinitionBuilder ReturnType(string? type) |
| | | 25 | | { |
| | 0 | 26 | | _functionDefinition.ReturnType = type; |
| | 0 | 27 | | return this; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Add a parameter to the function. |
| | | 32 | | /// </summary> |
| | | 33 | | public FunctionDefinitionBuilder Parameter(string name, string? type, bool isOptional = false) |
| | | 34 | | { |
| | 0 | 35 | | _functionDefinition.Parameters.Add(new (name, type, isOptional)); |
| | 0 | 36 | | return this; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Build a <see cref="FunctionDefinition"/> using the collected information. |
| | | 41 | | /// </summary> |
| | 0 | 42 | | public FunctionDefinition BuildFunctionDefinition() => new(_functionDefinition.Name, _functionDefinition.ReturnType, |
| | | 43 | | } |