public void ToUriTest() { var uriValue = new UriValue("http://www.webapiclient.com"); var uri = uriValue.ToUri(); Assert.Equal(new Uri("http://www.webapiclient.com"), uri); uriValue = new UriValue(new Uri("http://www.webapiclient.com")); uri = uriValue.ToUri(); Assert.Equal(new Uri("http://www.webapiclient.com"), uri); }
/// <summary> /// 创建新的uri /// </summary> /// <param name="uri">原始uri</param> /// <param name="keyValues">键值对</param> /// <returns></returns> protected virtual Uri CreateUri(Uri uri, IEnumerable <KeyValue> keyValues) { var uriValue = new UriValue(uri); foreach (var keyValue in keyValues) { uriValue = uriValue.Replace(keyValue.Key, keyValue.Value, out var replaced); if (replaced == false) { uriValue = uriValue.AddQuery(keyValue.Key, keyValue.Value); } } return(uriValue.ToUri()); }