Example #1
0
        private string RenderAttributeParameterValue(ServiceAttributeParameterInfo parameter)
        {
            if (s_unquotedAttributeValueRegex.IsMatch(parameter.Value))
            {
                return(parameter.Value);
            }

            return("\"" + s_escapeAttributeValueRegex.Replace(parameter.Value, RenderAttributeValueEscape) + "\"");
        }
Example #2
0
 private static HttpMethod GetHttpMethodFromParameter(ServiceAttributeParameterInfo parameter)
 {
     try
     {
         return(new HttpMethod(parameter.Value.ToUpperInvariant()));
     }
     catch (FormatException)
     {
         throw new ServiceDefinitionException($"Invalid HTTP method '{parameter.Value}'.", parameter.Position);
     }
 }
Example #3
0
        public static HttpStatusCode ParseStatusCodeInteger(ServiceAttributeParameterInfo parameter)
        {
            int valueAsInteger;

            int.TryParse(parameter.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out valueAsInteger);
            if (valueAsInteger < 200 || valueAsInteger >= 599)
            {
                throw new ServiceDefinitionException($"'{parameter.Name}' parameter must be an integer between 200 and 599.", parameter.Position);
            }
            return((HttpStatusCode)valueAsInteger);
        }
Example #4
0
        private protected HttpStatusCode?TryParseStatusCodeInteger(ServiceAttributeParameterInfo parameter)
        {
            int.TryParse(parameter.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var valueAsInteger);
            if (valueAsInteger < 200 || valueAsInteger >= 599)
            {
                AddValidationError(new ServiceDefinitionError($"'{parameter.Name}' parameter must be an integer between 200 and 599.", parameter.GetPart(ServicePartKind.Value)?.Position));
                return(null);
            }

            return((HttpStatusCode)valueAsInteger);
        }
Example #5
0
        private string GetHttpMethodFromParameter(ServiceAttributeParameterInfo parameter)
        {
            var httpMethod = parameter.Value.ToUpperInvariant();

            if (!s_httpMethods.Contains(httpMethod))
            {
                AddValidationError(new ServiceDefinitionError($"Unsupported HTTP method '{httpMethod}'.", parameter.GetPart(ServicePartKind.Value)?.Position));
                return(null);
            }

            return(httpMethod);
        }
Example #6
0
 public static ServiceDefinitionException CreateInvalidHttpParameterException(this ServiceAttributeParameterInfo parameter)
 {
     return(new ServiceDefinitionException($"Unexpected 'http' parameter '{parameter.Name}'.", parameter.Position));
 }
Example #7
0
 private protected void AddInvalidHttpParameterError(ServiceAttributeParameterInfo parameter) =>
 AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError("http", parameter));
Example #8
0
 private string RenderAttributeParameter(ServiceAttributeParameterInfo parameter)
 {
     return($"{parameter.Name}: {RenderAttributeParameterValue(parameter)}");
 }