public string GetLeftPart(UriPartial part)
{
if (IsNotAbsoluteUri)
{
throw new InvalidOperationException(SR.net_uri_NotAbsolute);
}
EnsureUriInfo();
const UriComponents NonPathPart = (UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port);
switch (part)
{
case UriPartial.Scheme:
return GetParts(UriComponents.Scheme | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
case UriPartial.Authority:
if (NotAny(Flags.AuthorityFound) || IsDosPath)
{
// V1.0 compatibility.
// It not return an empty string but instead "scheme:" because it is a LEFT part.
// Also neither it should check for IsDosPath here
// From V1.0 comments:
// anything that didn't have "//" after the scheme name
// (mailto: and news: e.g.) doesn't have an authority
//
return string.Empty;
}
return GetParts(NonPathPart, UriFormat.UriEscaped);
case UriPartial.Path:
return GetParts(NonPathPart | UriComponents.Path, UriFormat.UriEscaped);
case UriPartial.Query:
return GetParts(NonPathPart | UriComponents.Path | UriComponents.Query, UriFormat.UriEscaped);
}
throw new ArgumentException(SR.Format(SR.Argument_InvalidUriSubcomponent, part), nameof(part));
}