Esempio n. 1
0
 /// <summary>
 /// Converts to a <see cref="Uri"/>.
 /// </summary>
 public static Uri ToUri(this IUniformResourceIdentifierReference @this)
 {
     if (@this is RelativeReference relativeUri)
     {
         return(relativeUri.ToUri());
     }
     return(((IUniformResourceIdentifier)@this).ToUri());
 }
 /// <summary>
 /// Resolves a reference URI against a base URI. The reference URI may be relative or a URI.
 /// </summary>
 /// <typeparam name="T">The type of the base URI. This may be different than the type of the result.</typeparam>
 /// <param name="baseUri">The base URI.</param>
 /// <param name="referenceUri">The reference URI.</param>
 /// <param name="factory">The factory method used to create a new URI.</param>
 public static IUniformResourceIdentifier Resolve <T>(T baseUri, IUniformResourceIdentifierReference referenceUri, DelegateFactory <T> factory)
     where T : IUniformResourceIdentifier
 {
     // See 5.2.2, except we always do strict resolution.
     if (referenceUri is RelativeReference relativeReference)
     {
         return(Resolve(baseUri, relativeReference, factory));
     }
     return((IUniformResourceIdentifier)referenceUri);
 }
Esempio n. 3
0
 /// <summary>
 /// System.Uri is just awful at parsing URIs. Using Nito.UniformResourceIdentifiers
 /// </summary>
 /// <param name="uriString"></param>
 /// <param name="uri"></param>
 /// <returns></returns>
 private static bool TryCreateUri(string uriString, out IUniformResourceIdentifierReference uri)
 {
     try
     {
         uri = UniformResourceIdentifierReference.Parse(uriString);
         return(true);
     }
     catch
     {
         uri = null;
         return(false);
     }
 }
 /// <summary>
 /// Parses the query of the URI as a series of name/value pairs, e.g., "q=test&amp;page=4". This can be <c>null</c> if there is no query, or an empty collection if the query is empty. Names can be empty but never <c>null</c>; values can be <c>null</c> (if there is no <c>=</c>) or empty.
 /// </summary>
 public static IEnumerable <KeyValuePair <string, string> > QueryValues(this IUniformResourceIdentifierReference @this) =>
 @this.Query == null ? null : Util.FormUrlDecodeValues(@this.Query);
 /// <summary>
 /// Resolves a reference URI against this URI.
 /// </summary>
 /// <param name="referenceUri">The reference URI to resolve.</param>
 public IUniformResourceIdentifier Resolve(IUniformResourceIdentifierReference referenceUri) => Utility.Resolve(this, referenceUri, Factory);
 /// <summary>
 /// Parses the query of the URI as a series of name/value pairs, e.g., "q=test&amp;page=4". This can be <c>null</c> if there is no query, or an empty collection if the query is empty. Names can be empty but never <c>null</c>; values can be <c>null</c> (if there is no <c>=</c>) or empty.
 /// </summary>
 public static IEnumerable <KeyValuePair <string, string> >?QueryValues(this IUniformResourceIdentifierReference @this)
 {
     _ = @this ?? throw new ArgumentNullException(nameof(@this));
     return(@this.Query == null ? null : Utility.FormUrlDecodeValues(@this.Query));
 }
Esempio n. 7
0
 /// <summary>
 /// Deconstructs a URI reference into this builder.
 /// </summary>
 /// <param name="builder">The builder to modify.</param>
 /// <param name="uri">The URI reference to deconstruct.</param>
 public static T ApplyUriReference <T>(T builder, IUniformResourceIdentifierReference uri)
     where T : ICommonBuilder <T>
 {
     _ = uri ?? throw new ArgumentNullException(nameof(uri));
     return(ApplyUriReference(builder, uri.UserInfo, uri.Host, uri.Port, uri.PathSegments, uri.Query, uri.Fragment));
 }
 /// <summary>
 /// Returns <c>true</c> if the path is empty.
 /// </summary>
 public static bool PathIsEmpty(this IUniformResourceIdentifierReference @this)
 {
     _ = @this ?? throw new ArgumentNullException(nameof(@this));
     return(PathIsEmpty(@this.PathSegments));
 }
 /// <summary>
 /// Returns <c>true</c> if the authority is defined. Note that it is possible (though unusual) for the authority to be defined as the empty string.
 /// </summary>
 public static bool AuthorityIsDefined(this IUniformResourceIdentifierReference @this)
 {
     _ = @this ?? throw new ArgumentNullException(nameof(@this));
     return(@this.UserInfo != null || @this.Host != null || @this.Port != null);
 }
 /// <summary>
 /// Deconstructs a URI reference into this builder.
 /// </summary>
 /// <param name="builder">The builder to modify.</param>
 /// <param name="uri">The URI reference to deconstruct.</param>
 public static T ApplyUriReference <T>(T builder, IUniformResourceIdentifierReference uri)
     where T : ICommonBuilder <T> => ApplyUriReference(builder, uri.UserInfo, uri.Host, uri.Port, uri.PathSegments, uri.Query, uri.Fragment);
Esempio n. 11
0
 /// <summary>
 /// Returns <c>true</c> if the path is empty.
 /// </summary>
 public static bool PathIsEmpty(this IUniformResourceIdentifierReference @this) => PathIsEmpty(@this.PathSegments);
Esempio n. 12
0
 /// <summary>
 /// Returns <c>true</c> if the authority is defined. Note that it is possible (though unusual) for the authority to be defined as the empty string.
 /// </summary>
 public static bool AuthorityIsDefined(this IUniformResourceIdentifierReference @this) => @this.UserInfo != null || @this.Host != null || @this.Port != null;