Sphyrnidae Common Library  2.0.1
Shared Utilities/Library
Sphyrnidae.Common.Paths.UrlBuilder Class Reference

There is already a UriBuilder, so didn't want to reuse that name. This is a much nicer interface though for truly building out a URI More...

Public Member Functions

 UrlBuilder ()
 Empty Constructor: You must specify all aspects of the URL More...
 
 UrlBuilder (string uri)
 Constructor: Allows you to modify the URL safely More...
 
UrlBuilder AsHttp ()
 Sets the url scheme to "http" More...
 
UrlBuilder AsHttps ()
 Sets the url scheme to "https" More...
 
UrlBuilder WithScheme (string scheme)
 Sets the url scheme to whatever you pass in More...
 
UrlBuilder WithHost (string host)
 Updates the "host" part of the url (eg. the main part) More...
 
UrlBuilder WithPort (int port)
 Updates the "port" part of the url (eg. 80) More...
 
UrlBuilder ClearPathSegments ()
 If you wish to remove all path segments to build new ones (existing segments can be retrieved via public property) More...
 
UrlBuilder RemoveFirstSegment ()
 Removes the first path segment More...
 
UrlBuilder RemoveLastSegment ()
 Removes the last path segment More...
 
UrlBuilder AddPathSegment (string segment)
 Adds a segment to the URL More...
 
UrlBuilder AddPathSegmentToBeginning (string segment)
 Adds a segment to the beginning of the segment part of the URL More...
 
UrlBuilder ClearQueryString ()
 Removes all items from the query string More...
 
UrlBuilder RemoveFromQueryString (string key)
 Removes an item from the query string. If key not found, this does nothing More...
 
UrlBuilder AddQueryString (string key, string value)
 Adds a key and value combination to the query string (parameters are raw text, the actual URL will have these properly escaped) More...
 
UrlBuilder WithFragment (string fragment)
 Sets the fragment for the url More...
 
string Build ()
 Must be called last More...
 

Properties

List< string > Segments = new List<string>() [get]
 

Detailed Description

There is already a UriBuilder, so didn't want to reuse that name. This is a much nicer interface though for truly building out a URI

Constructor & Destructor Documentation

◆ UrlBuilder() [1/2]

Sphyrnidae.Common.Paths.UrlBuilder.UrlBuilder ( )

Empty Constructor: You must specify all aspects of the URL

◆ UrlBuilder() [2/2]

Sphyrnidae.Common.Paths.UrlBuilder.UrlBuilder ( string  uri)

Constructor: Allows you to modify the URL safely

Parameters
uriThe initial URL

Member Function Documentation

◆ AddPathSegment()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.AddPathSegment ( string  segment)

Adds a segment to the URL

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
segmentThe segment to add
Returns
The UrlBuilder so you can chain/build

◆ AddPathSegmentToBeginning()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.AddPathSegmentToBeginning ( string  segment)

Adds a segment to the beginning of the segment part of the URL

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
segmentThe segment to add
Returns
The UrlBuilder so you can chain/build

◆ AddQueryString()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.AddQueryString ( string  key,
string  value 
)

Adds a key and value combination to the query string (parameters are raw text, the actual URL will have these properly escaped)

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
keyThe key (eg. key=value)
valueThe value (eg. key=value)
Returns
The UrlBuilder so you can chain/build

◆ AsHttp()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.AsHttp ( )

Sets the url scheme to "http"

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ AsHttps()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.AsHttps ( )

Sets the url scheme to "https"

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ Build()

string Sphyrnidae.Common.Paths.UrlBuilder.Build ( )

Must be called last

Returns
The fully built URL you pieced together using the UrlBuilder class

◆ ClearPathSegments()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.ClearPathSegments ( )

If you wish to remove all path segments to build new ones (existing segments can be retrieved via public property)

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ ClearQueryString()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.ClearQueryString ( )

Removes all items from the query string

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ RemoveFirstSegment()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.RemoveFirstSegment ( )

Removes the first path segment

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ RemoveFromQueryString()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.RemoveFromQueryString ( string  key)

Removes an item from the query string. If key not found, this does nothing

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
keyThe key (eg. key=value)
Returns
The UrlBuilder so you can chain/build

◆ RemoveLastSegment()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.RemoveLastSegment ( )

Removes the last path segment

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Returns
The UrlBuilder so you can chain/build

◆ WithFragment()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.WithFragment ( string  fragment)

Sets the fragment for the url

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
fragmentThe fragment to use
Returns
The UrlBuilder so you can chain/build

◆ WithHost()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.WithHost ( string  host)

Updates the "host" part of the url (eg. the main part)

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
hostThe "host" part of the URL
Returns
The UrlBuilder so you can chain/build

◆ WithPort()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.WithPort ( int  port)

Updates the "port" part of the url (eg. 80)

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
portThe port for the host in the url
Returns
The UrlBuilder so you can chain/build

◆ WithScheme()

UrlBuilder Sphyrnidae.Common.Paths.UrlBuilder.WithScheme ( string  scheme)

Sets the url scheme to whatever you pass in

<scheme>://<host>:<port>/<path segment 1>/<path segment 2>?<query key 1>=<query value 1>&<query key 2>=<query value 2>#<fragment>

Parameters
schemeThe url scheme
Returns
The UrlBuilder so you can chain/build

Property Documentation

◆ Segments

List<string> Sphyrnidae.Common.Paths.UrlBuilder.Segments = new List<string>()
get

The documentation for this class was generated from the following file: