| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Specialized; |
| | | 5 | | using System.Text; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF |
| | | 9 | | { |
| | | 10 | | internal class UriTemplateVariableQueryValue : UriTemplateQueryValue |
| | | 11 | | { |
| | | 12 | | private readonly string _varName; |
| | | 13 | | |
| | | 14 | | public UriTemplateVariableQueryValue(string varName) |
| | 29 | 15 | | : base(UriTemplatePartType.Variable) |
| | | 16 | | { |
| | | 17 | | Fx.Assert(!string.IsNullOrEmpty(varName), "bad variable segment"); |
| | 29 | 18 | | _varName = varName; |
| | 29 | 19 | | } |
| | | 20 | | |
| | | 21 | | public override void Bind(string keyName, string[] values, ref int valueIndex, StringBuilder query) |
| | | 22 | | { |
| | | 23 | | Fx.Assert(valueIndex < values.Length, "Not enough values to bind"); |
| | | 24 | | |
| | 0 | 25 | | if (values[valueIndex] == null) |
| | | 26 | | { |
| | 0 | 27 | | valueIndex++; |
| | | 28 | | } |
| | | 29 | | else |
| | | 30 | | { |
| | 0 | 31 | | query.AppendFormat("&{0}={1}", UrlUtility.UrlEncode(keyName, Encoding.UTF8), UrlUtility.UrlEncode(values |
| | | 32 | | } |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | public override bool IsEquivalentTo(UriTemplateQueryValue other) |
| | | 36 | | { |
| | 0 | 37 | | if (other == null) |
| | | 38 | | { |
| | | 39 | | Fx.Assert("why would we ever call this?"); |
| | | 40 | | |
| | 0 | 41 | | return false; |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | return other.Nature == UriTemplatePartType.Variable; |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public override void Lookup(string value, NameValueCollection boundParameters) |
| | | 48 | | { |
| | 1 | 49 | | boundParameters.Add(_varName, value); |
| | 1 | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |