#53 - implicitly convert System.Uri to Flurl.Url

This commit is contained in:
tmenier 2016-05-13 16:22:12 -05:00
parent 3983493592
commit fae2680707
2 changed files with 14 additions and 0 deletions

View File

@ -290,5 +290,13 @@ namespace Flurl
public static implicit operator Url(string url) {
return new Url(url);
}
/// <summary>
/// Implicit conversion from System.Uri to Flurl.Url.
/// </summary>
/// <returns>The string</returns>
public static implicit operator Url(Uri uri) {
return new Url(uri.ToString());
}
}
}

View File

@ -189,5 +189,11 @@ namespace Flurl.Test.Http
CollectionAssert.IsNotEmpty(client4.GetCookies());
}
[Test]
public void can_use_uri_with_WithUrl() {
var uri = new System.Uri("http://www.mysite.com/foo?x=1");
var fc = new FlurlClient().WithUrl(uri);
Assert.AreEqual(uri.ToString(), fc.Url.ToString());
}
}
}