| | | 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; |
| | | 5 | | using System.Collections.Specialized; |
| | | 6 | | using System.Text; |
| | | 7 | | using CoreWCF.Runtime; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | // thin wrapper around string; use type system to help ensure we |
| | | 12 | | // are doing canonicalization right/consistently |
| | | 13 | | internal class UriTemplateLiteralQueryValue : UriTemplateQueryValue, IComparable<UriTemplateLiteralQueryValue> |
| | | 14 | | { |
| | | 15 | | private readonly string _value; // an unescaped representation |
| | | 16 | | |
| | | 17 | | private UriTemplateLiteralQueryValue(string value) |
| | 0 | 18 | | : base(UriTemplatePartType.Literal) |
| | | 19 | | { |
| | | 20 | | Fx.Assert(value != null, "bad literal value"); |
| | 0 | 21 | | _value = value; |
| | 0 | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | public static UriTemplateLiteralQueryValue CreateFromUriTemplate(string value) => new UriTemplateLiteralQueryVal |
| | | 25 | | |
| | 0 | 26 | | public string AsEscapedString() => UrlUtility.UrlEncode(_value, Encoding.UTF8); |
| | | 27 | | |
| | 0 | 28 | | public string AsRawUnescapedString() => _value; |
| | | 29 | | |
| | | 30 | | public override void Bind(string keyName, string[] values, ref int valueIndex, StringBuilder query) |
| | | 31 | | { |
| | 0 | 32 | | query.AppendFormat("&{0}={1}", UrlUtility.UrlEncode(keyName, Encoding.UTF8), AsEscapedString()); |
| | 0 | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | public int CompareTo(UriTemplateLiteralQueryValue other) => string.Compare(_value, other._value, StringCompariso |
| | | 36 | | |
| | | 37 | | public override bool Equals(object obj) |
| | | 38 | | { |
| | 0 | 39 | | if (!(obj is UriTemplateLiteralQueryValue lqv)) |
| | | 40 | | { |
| | | 41 | | Fx.Assert("why would we ever call this?"); |
| | 0 | 42 | | return false; |
| | | 43 | | } |
| | | 44 | | else |
| | | 45 | | { |
| | 0 | 46 | | return _value == lqv._value; |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | public override int GetHashCode() => _value.GetHashCode(); |
| | | 51 | | |
| | | 52 | | public override bool IsEquivalentTo(UriTemplateQueryValue other) |
| | | 53 | | { |
| | 0 | 54 | | if (other == null) |
| | | 55 | | { |
| | | 56 | | Fx.Assert("why would we ever call this?"); |
| | 0 | 57 | | return false; |
| | | 58 | | } |
| | | 59 | | |
| | 0 | 60 | | if (other.Nature != UriTemplatePartType.Literal) |
| | | 61 | | { |
| | 0 | 62 | | return false; |
| | | 63 | | } |
| | | 64 | | |
| | 0 | 65 | | UriTemplateLiteralQueryValue otherAsLiteral = other as UriTemplateLiteralQueryValue; |
| | | 66 | | Fx.Assert(otherAsLiteral != null, "The nature requires that this will be OK"); |
| | | 67 | | |
| | 0 | 68 | | return CompareTo(otherAsLiteral) == 0; |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | public override void Lookup(string value, NameValueCollection boundParameters) |
| | | 72 | | { |
| | | 73 | | Fx.Assert(string.Compare(_value, value, StringComparison.Ordinal) == 0, "How can that be?"); |
| | 0 | 74 | | } |
| | | 75 | | } |
| | | 76 | | } |