/// <summary>
 /// Constructs an attribute that defines a parameter that is expected by a service endpoint.
 /// This version of the constructor is for the case where the attribute is attached to a method
 /// </summary>
 /// <param name="parameterName">The name of the parameter. This will be the name
 /// if the query string parameter, custom header, form field etc</param>
 /// <param name="parserType">A type that provides parsing and validation. This type must have a default public constructor</param>
 /// <param name="parameterType">Bit flags indicating which methods of providing the parameter are allowed</param>
 public EndpointParameterAttribute(
     string parameterName,
     Type parserType,
     EndpointParameterType parameterType = EndpointParameterType.QueryString)
 {
     ParameterName = parameterName;
     ParserType    = parserType;
     ParameterType = parameterType;
 }
        public void AddParameter(string name, EndpointParameterType parameterType, IParameterParser parser)
        {
            var functions = new List <Func <IEndpointRequest, string, string> >();

            if (parameterType.HasFlag(EndpointParameterType.QueryString))
            {
                functions.Add(QueryStringParam);
            }

            if (parameterType.HasFlag(EndpointParameterType.Header))
            {
                functions.Add(HeaderParam);
            }

            if (parameterType.HasFlag(EndpointParameterType.PathSegment))
            {
                var placeholder = "{" + name + "}";
                for (var i = 0; i < _pathElements.Length; i++)
                {
                    var index = i;
                    if (string.Equals(placeholder, _pathElements[i], StringComparison.OrdinalIgnoreCase))
                    {
                        functions.Add((r, n) => PathSegmentParam(r, index));
                        break;
                    }
                }
            }

            if (parameterType.HasFlag(EndpointParameterType.FormField))
            {
                functions.Add(FormFieldParam);
            }

            var parameter = new EndpointParameter
            {
                Name          = name,
                ParameterType = parameterType,
                Parser        = parser,
                Functions     = functions.ToArray()
            };

            if (_parameters == null)
            {
                _parameters = new[] { parameter };
            }
            else
            {
                var parameters = _parameters.ToList();
                parameters.Add(parameter);
                _parameters = parameters.ToArray();
            }
        }
 /// <summary>
 /// Constructs an attribute that defines a parameter that is expected by a service endpoint
 /// This version of the constructor is for the case where the attribute is attached to a parameter
 /// </summary>
 /// <param name="parameterType">Bit flags indicating which methods of providing the parameter are allowed</param>
 public EndpointParameterAttribute(
     EndpointParameterType parameterType = EndpointParameterType.QueryString)
 {
     ParameterType = parameterType;
 }