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))
                {
                    string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                              segment.Substring(1, segment.Length - 3));
                    return(new UriTemplateVariablePathSegment(segment, true, varName));
                }
                else
                {
                    string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                              segment.Substring(1, segment.Length - 2));
                    return(new UriTemplateVariablePathSegment(segment, false, varName));
                }

            default:
                Fx.Assert("Invalid value from IdentifyStringNature");
                return(null);
            }
        }
        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);
            }
        }
Exemple #3
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);
        }
        public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
        {
            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))
                {
                    return(new UriTemplateVariablePathSegment(segment, false, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 2))));
                }
                return(new UriTemplateVariablePathSegment(segment, true, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 3))));
            }
            return(null);
        }