Exemple #1
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");
            }
        }