Exemplo n.º 1
0
        /// <summary>
        /// Parse input parameters string and returns list of input parameters values
        /// </summary>
        /// <param name="templateProcessor">Template processor that will be used for parameters specified as templates</param>
        /// <param name="dataItem">Data item that will be used for parameters specified as data item templates</param>
        protected virtual IList <InputParameter> GetInputParametersValues(string inputParamsAsString, ITemplateProcessor templateProcessor, HierarchicalDataItem dataItem)
        {
            IList <InputParameter> inputParameters = new List <InputParameter>();
            string pattern = templateProcessor.UnwrapTemplate(templateProcessor.GetFullRegexPattern(), true);

            foreach (string p in ParseInputParams(inputParamsAsString))
            {
                if (p.StartsWith("\"") && p.EndsWith("\""))
                {
                    inputParameters.Add(new InputParameter
                    {
                        Value = p.Substring(1, p.Length - 2),
                        Type  = typeof(string),
                    });
                }
                else if (Regex.IsMatch(p, $@"^{pattern}$"))
                {
                    object value = templateProcessor.GetValue(p, dataItem);
                    inputParameters.Add(new InputParameter
                    {
                        Value = value,
                        Type  = value?.GetType(),
                    });
                }
                else
                {
                    object value = p;
                    Type   type  = null;
                    Match  match = Regex.Match(p, @"^\[(.+)\](.+)$");
                    if (match.Success)
                    {
                        type  = GetTypeByCode(match.Groups[1].Value);
                        value = Convert.ChangeType(match.Groups[2].Value.Trim(), type);
                    }
                    inputParameters.Add(new InputParameter {
                        Value = value, Type = type
                    });
                }
            }
            return(inputParameters);
        }