private List<QueryParameter> ExtractParameters(Query query)
        {
            //parameters are of the form [[param_name]]
            var parameters =  new List<QueryParameter>();
            var pattern = new Regex(@"\[\[\w+\|?[\w\s]*\]\]"); //matches items like [[product_id]]
            var matches = pattern.Matches(query.Text);

            if (matches.Count == 0) return parameters;
            int paraCount = 0;
            foreach (var match in matches)
            {
                var paraArray = match.ToString().Trim(new char[]{'[',']'}).Split('|');

                var param = new QueryParameter()
                            {
                                Name = paraArray[0],
                                Description = paraArray.Length > 1 ? paraArray[1] : string.Empty,
                                ParameterNumber = paraCount++,
                            };
                parameters.Add(param);
            }

            return parameters;
        }
示例#2
0
 private void AssociateParameter(QueryParameter parameter)
 {
     if (Parameters.Any(queryParameter => queryParameter.Name.ToUpperInvariant().Equals(parameter.Name.ToUpperInvariant())))
     {
         return;
     }
     Parameters.Add(parameter);
 }