Пример #1
0
 /// <summary>
 /// 创建 RouteRequestData 对象
 /// </summary>
 /// <param name="request"></param>
 public RouteRequestData(HttpRequestMessage request)
 {
     Path        = PathSegments.Create(request.RequestUri.AbsolutePath);
     Host        = HostSegments.Create(request.RequestUri.Host);
     Scheme      = request.RequestUri.Scheme;
     QueryString = new ReadOnlyCollection <(string name, string value)>(ParseQueryString(request.RequestUri.Query).ToArray());
 }
    public IDictionary<string, string> GetRouteValues( PathSegments pathSegments )
    {

      var values = new Dictionary<string, string>();


      var i = 0;
      foreach ( var segment in pathSegments )
      {
        var template = segments[i];
        switch ( template.Type )
        {
          case SegmentType.Static:
            if ( stringComparer.Equals( template.Value, segment ) == false )
              return null;

            i++;
            break;

          case SegmentType.Dynamic:
            values[template.Value] = segment;

            i++;
            break;

          case SegmentType.InfinityDynamic:
            if ( values.ContainsKey( template.Value ) == false )
              values[template.Value] = segment;

            else
              values[template.Value] += "/" + segment;

            break;
        }
      }


      var lastSegment = segments[segments.Length - 1];
      //infinity dynamic is not i++.
      if ( lastSegment.Type == SegmentType.InfinityDynamic )
      {
        i++;
        if ( values.ContainsKey( lastSegment.Value ) == false )
          values[lastSegment.Value] = null;
      }


      if ( i < segments.Length )
        return null;

      return values;
    }
Пример #3
0
 internal IDictionary <string, string> GetRouteValues(PathSegments path)
 {
     return(new Dictionary <string, string>());
 }