Exemplo n.º 1
0
        public static UriTemplateQueryValue CreateFromUriTemplate(string value, UriTemplate template)
        {
            // Checking for empty value
            if (value == null)
            {
                return(UriTemplateQueryValue.Empty);
            }
            // Identifying the type of value - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(value))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralQueryValue.CreateFromUriTemplate(value));

            case UriTemplatePartType.Compound:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(
                                                                                                            SR.UTQueryCannotHaveCompoundValue, template.originalTemplate)));

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

            default:
                Fx.Assert("Invalid value from IdentifyStringNature");
                return(null);
            }
        }
Exemplo n.º 2
0
        public static UriTemplateQueryValue CreateFromUriTemplate(string value, UriTemplate template)
        {
            if (value == null)
            {
                return(Empty);
            }
            switch (UriTemplateHelpers.IdentifyPartType(value))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralQueryValue.CreateFromUriTemplate(value));

            case UriTemplatePartType.Compound:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("UTQueryCannotHaveCompoundValue", new object[] { template.originalTemplate })));

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