diff --git a/PowerAutomateMockUp/ExpressionParser/Functions/Implementations/Miscellaneous/ParametersFunction.cs b/PowerAutomateMockUp/ExpressionParser/Functions/Implementations/Miscellaneous/ParametersFunction.cs new file mode 100644 index 0000000..480c846 --- /dev/null +++ b/PowerAutomateMockUp/ExpressionParser/Functions/Implementations/Miscellaneous/ParametersFunction.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Microsoft.Extensions.Options; +using Parser.ExpressionParser.Functions.Base; +using Parser.ExpressionParser.Functions.CustomException; + +namespace Parser.ExpressionParser.Functions.Implementations.Miscellaneous +{ + public class ParametersFunction : Function + { + private readonly WorkflowParameters _flowParameters; + + public ParametersFunction(IOptions flowParameters) : base("parameters") + { + _flowParameters = flowParameters?.Value; + } + + public override ValueContainer ExecuteFunction(params ValueContainer[] parameters) + { + var paramKey = parameters.FirstOrDefault(); + + if (paramKey == null || paramKey.Type() != ValueContainer.ValueType.String) + { + throw new ArgumentError("The parameters functions is expected to have one argument of type string"); + } + + if (_flowParameters?.Parameters == null) + { + return paramKey; + } + + if (_flowParameters.Parameters.ContainsKey(paramKey.GetValue())) + { + return _flowParameters.Parameters[paramKey.GetValue()]; + } + + throw InvalidTemplateException.BuildInvalidLanguageFunction("ActionName", "parameters"); + } + } +} \ No newline at end of file diff --git a/PowerAutomateMockUp/WorkflowParameters.cs b/PowerAutomateMockUp/WorkflowParameters.cs new file mode 100644 index 0000000..ade7dab --- /dev/null +++ b/PowerAutomateMockUp/WorkflowParameters.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using Parser.ExpressionParser; + +namespace Parser +{ + public class WorkflowParameters + { + public Dictionary Parameters { get; set; } + } +} \ No newline at end of file