public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
        {
            // Identifying the type of segment - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(segment))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Compound:
                return(UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Variable:
                if (segment.EndsWith("/", StringComparison.Ordinal))
                {
                    var varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                           segment.Substring(1, segment.Length - 3));
                    return(new UriTemplateVariablePathSegment(segment, true, varName));
                }
                else
                {
                    var varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                           segment.Substring(1, segment.Length - 2));
                    return(new UriTemplateVariablePathSegment(segment, false, varName));
                }

            default:
                throw new Exception("Invalid value from IdentifyStringNature");
            }
        }
 private void PopulateQueryParameters()
 {
     if (_requestUri != null)
     {
         _queryParameters = UriTemplateHelpers.ParseQueryString(_requestUri.Query);
     }
     else
     {
         _queryParameters = new NameValueCollection();
     }
 }
示例#3
0
        public static UriTemplateQueryValue CreateFromUriTemplate(string value, UriTemplate template)
        {
            // Checking for empty value
            if (value == null)
            {
                return(Empty);
            }
            // Identifying the type of value - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(value))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralQueryValue.CreateFromUriTemplate(value));

            case UriTemplatePartType.Compound:
                throw new InvalidOperationException("UTQueryCannotHaveCompoundValue");

            case UriTemplatePartType.Variable:
                return(new UriTemplateVariableQueryValue(template.AddQueryVariable(value.Substring(1, value.Length - 2))));

            default:
                throw new Exception("Invalid value from IdentifyStringNature");
            }
        }