Esempio n. 1
0
        /// <summary>
        /// Gets the possible parameter types.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Possible parameter types</returns>
        public static IEnumerable <PossibleParameterType> GetPossibleParameterTypes(this HttpRequest request)
        {
            if (request.HasBody())
            {
                yield return(new PossibleParameterType
                {
                    Source = ParameterSources.Body,
                    HasValue = true,
                    OrderId = 0
                });
            }
            int queryOrder = 0;

            foreach (var param in request.Query)
            {
                var possibleType = new PossibleParameterType
                {
                    Source            = ParameterSources.Query,
                    Name              = param.Key,
                    OrderId           = queryOrder,
                    QueryValues       = param.Value,
                    HasNonEmptyValue  = param.Value.Count > 0 && param.Value.Any(x => x.Length > 0),
                    HasMultipleValues = param.Value.Count > 1
                };

                if (possibleType.QueryValues.Any())
                {
                    string first = possibleType.QueryValues.FirstOrDefault();
                    if (!string.IsNullOrEmpty(first))
                    {
                        possibleType.PossibleTypes = GetPossibleTypes(first).Select(x => new TypeWithPriority(x)).ToArray();
                    }
                }

                yield return(possibleType);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Determines whether the specified possible parameter is matched by name.
 /// </summary>
 /// <param name="possibleParam">The possible parameter.</param>
 /// <param name="actionParam">The action parameter.</param>
 /// <returns>True is match is found</returns>
 public static bool IsMatchedByName(this PossibleParameterType possibleParam, ActionParameter actionParam)
 => actionParam.Name == possibleParam.Name;