Exemple #1
0
 private static PlaceholderGenerator getPlaceholderGenerator(string prefix, Variable[] variables)
 {
     if (prefix == "+")
     {
         return new PlaceholderGenerator(variables) { AreReservedCharactersAllowed = true };
     }
     else if (prefix == "#")
     {
         return new PlaceholderGenerator(variables) { Prefix = "#", AreReservedCharactersAllowed = true };
     }
     else if (prefix == ".")
     {
         return new PlaceholderGenerator(variables) { Prefix = ".", Separator = "." };
     }
     else if (prefix == "/")
     {
         return new PlaceholderGenerator(variables) { Prefix = "/", Separator = "/" };
     }
     else if (prefix == ";")
     {
         return new PlaceholderGenerator(variables) { Prefix = ";", Separator = ";", IsQualified = true };
     }
     else if (prefix == "?")
     {
         return new PlaceholderGenerator(variables) { Prefix = "?", Separator = "&", IsQualified = true, IsQualifiedWhenEmpty = true };
     }
     else if (prefix == "&")
     {
         return new PlaceholderGenerator(variables) { Prefix = "&", Separator = "&", IsQualified = true, IsQualifiedWhenEmpty = true };
     }
     else
     {
         return new PlaceholderGenerator(variables);
     }
 }
 private object escape(Variable variable, object value)
 {
     if (value == null)
     {
         return null;
     }
     var pair = value as Tuple<string, object>;
     if (pair != null)
     {
         string pairKey = escape(variable, pair.Item1);
         string unescaped = pair.Item2 == null ? null : pair.Item2.ToString();
         string pairValue = escape(variable, unescaped);
         return new Tuple<string, string>(pairKey, pairValue);
     }
     return escape(variable, value.ToString());
 }
 private string escape(Variable variable, string value)
 {
     if (value == null)
     {
         return null;
     }
     if (variable.MaxLength < value.Length)
     {
         value = value.Substring(0, variable.MaxLength.Value);
     }
     if (AreReservedCharactersAllowed)
     {
         return value.Replace(" ", "+");
     }
     else
     {
         return WebUtility.UrlEncode(value);
     }
 }
 private string qualify(Variable variable, object value)
 {
     var pair = value as Tuple<string, string>;
     if (pair != null)
     {
         return pair.Item1 + "=" + pair.Item2;
     }
     string stringValue = value as String;
     if (stringValue == null)
     {
         return null;
     }
     if (!IsQualified)
     {
         return stringValue;
     }
     if (!IsQualifiedWhenEmpty && String.IsNullOrWhiteSpace(stringValue))
     {
         return variable.Name;
     }
     return variable.Name + "=" + stringValue;
 }
 private object[] getSubstitutions(Variable variable, IProperty property)
 {
     var values = getParameterValues(variable, property);
     var parts = values.Select(v => escape(variable, v)).ToArray();
     if (variable.IsExploded)
     {
         return parts;
     }
     else
     {
         string combined = String.Join(",", parts);
         return new object[] { combined };
     }
 }
 private IEnumerable<object> getParameterValues(Variable variable, IProperty property)
 {
     return PropertyLookup.GetValues(property, variable.IsExploded);
 }