Added support for UriComponents.SerializationInfoString.
private UriParser Parser {
get {
if (parser == null) {
- parser = UriParser.GetParser (Scheme);
+ parser = UriParser.GetParser (scheme);
// no specific parser ? then use a default one
if (parser == null)
parser = new DefaultUriParser ("*");
public string GetComponents (UriComponents components, UriFormat format)
{
+ if ((components & UriComponents.SerializationInfoString) == 0)
+ EnsureAbsoluteUri ();
+
return Parser.GetComponents (this, components, format);
}
if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped))
throw new ArgumentOutOfRangeException ("format");
+ if ((components & UriComponents.SerializationInfoString) != 0) {
+ if (components != UriComponents.SerializationInfoString)
+ throw new ArgumentOutOfRangeException ("components", "UriComponents.SerializationInfoString must not be combined with other UriComponents.");
+
+ if (!uri.IsAbsoluteUri)
+ return UriHelper.FormatRelative (uri.OriginalString, "", format);
+
+ components |= UriComponents.AbsoluteUri;
+ }
+
return GetComponentsHelper (uri, components, format);
}
Assert.IsTrue (Uri.TryCreate (mainUri, uriPath, out result), "#1");
Assert.AreEqual ("http://www.imdb.com/title/tt0106521", result.ToString (), "#2");
}
+
+ [Test]
+ public void GetSerializationInfoStringOnRelativeUri ()
+ {
+ var uri = new Uri ("/relative/path", UriKind.Relative);
+ var result = uri.GetComponents (UriComponents.SerializationInfoString, UriFormat.UriEscaped);
+
+ Assert.AreEqual (uri.OriginalString, result);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void GetSerializationInfoStringException ()
+ {
+ var uri = new Uri ("/relative/path", UriKind.Relative);
+ uri.GetComponents (UriComponents.SerializationInfoString | UriComponents.Host, UriFormat.UriEscaped);
+ }
}
// Tests non default IriParsing