Exemplo n.º 1
0
        public string ToUrl(ResolvedRouteValues values)
        {
            var sb = new StringBuilder(_length);
            var i  = 0;

            for (var index = 0; index < _tokenized.Length; index++)
            {
                var t = _tokenized[index];
                if (t[0] == '@')
                {
                    if (values.TryGetValue(_parts[i], out var v))
                    {
                        if (string.IsNullOrEmpty(v))
                        {
                            throw new Exception($"'{_parts[i]}' defined but is empty on url: {_route}");
                        }

                        sb.Append(Uri.EscapeDataString(v));
                    }
                    else
                    {
                        throw new Exception($"No value provided for '{_parts[i]}' on url: {_route}");
                    }

                    i++;
                }
                else
                {
                    sb.Append(t);
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
 public bool Matches(ResolvedRouteValues values)
 {
     for (var i = 0; i < _parts.Length; i++)
     {
         if (!values.ContainsKey(_parts[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        internal ResolvedRouteValues Resolve(IConnectionSettingsValues configurationValues)
        {
            var resolved = new ResolvedRouteValues();

            foreach (var kv in this)
            {
                var value = this[kv.Key].GetString(configurationValues);
                if (!value.IsNullOrEmpty())
                {
                    resolved[kv.Key] = value;
                }
            }
            Resolved = resolved;
            return(resolved);
        }
Exemplo n.º 4
0
        private RouteValues Route(string name, IUrlParameter routeValue, bool required = true)
        {
            switch (routeValue)
            {
            case null when !required: {
                if (!ContainsKey(name))
                {
                    return(this);
                }

                Remove(name);
                Resolved = null;                         //invalidate cache
                return(this);
            }

            case null: throw new ArgumentNullException(name, $"{name} is required to build a url to this API");

            default:
                this[name] = routeValue;
                Resolved   = null;                       //invalidate cache
                return(this);
            }
        }