//
// This method is invoked to allow a custom parser to override the
// internal parser when serving application with Uri component strings.
// The output format depends on the "format" parameter
//
// Parameters:
// uriComponents - Which components are to be retrieved.
// uriFormat - The requested output format.
//
// This method returns:
// The final result. The base implementation could be invoked to get a suggested value
//
protected virtual string GetComponents(Uri uri, UriComponents components, UriFormat format)
{
if (((components & UriComponents.SerializationInfoString) != 0) && components != UriComponents.SerializationInfoString)
{
throw new ArgumentOutOfRangeException(nameof(components), components, SR.net_uri_NotJustSerialization);
}
if ((format & ~UriFormat.SafeUnescaped) != 0)
{
throw new ArgumentOutOfRangeException(nameof(format));
}
if (uri.UserDrivenParsing)
{
throw new InvalidOperationException(SR.Format(SR.net_uri_UserDrivenParsing, this.GetType()));
}
if (!uri.IsAbsoluteUri)
{
throw new InvalidOperationException(SR.net_uri_NotAbsolute);
}
if (uri.DisablePathAndQueryCanonicalization && (components & (UriComponents.Path | UriComponents.Query)) != 0)
{
throw new InvalidOperationException(SR.net_uri_GetComponentsCalledWhenCanonicalizationDisabled);
}
return(uri.GetComponentsHelper(components, format));
}