Class Validate
Provides validation methods for method arguments.
Inherited Members
Namespace: EmbedIO.Utilities
Syntax
public static class Validate
Methods
HttpHeaderName(String, String)
Ensures that a langword_csharp_string argument is valid as an HTTP header name as defined by RFC7230, Section 3.2.
The rules for valid HTTP header names are defined by RFC7230 to be the same as for RFC2616 tokens; for further information, please see the documentation for the Rfc2616Token(String, String, String) method.
Declaration
public static string HttpHeaderName(string argumentName, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
Returns
| Type | Description |
|---|---|
| String |
|
HttpHeaderValue(String, String)
Ensures that a langword_csharp_string argument is valid as an HTTP header value as defined by RFC7230, Section 3.2.
Only visible ASCII visible characters, plus space and horizontal tab, are allowed.
null is allowed, but it is turned into the empty string.
Obsolete line folding (see Section 3.2.4)
is NOT allowed, even if it is still allowed by Microsoft's
Declaration
public static string HttpHeaderValue(string argumentName, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
Returns
| Type | Description |
|---|---|
| String |
|
LocalPath(String, String, Boolean)
Ensures that the value of an argument is a valid local path and, optionally, gets the corresponding full path.
Declaration
public static string LocalPath(string argumentName, string value, bool getFullPath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
| Boolean | getFullPath | true to get the full path, false to leave the path as is.. |
Returns
| Type | Description |
|---|---|
| String | The local path, or the full path if |
MimeType(String, String, Boolean)
Ensures that a langword_csharp_string argument is valid as MIME type or media range as defined by RFC7231, Section 5,3.2.
Declaration
public static string MimeType(string argumentName, string value, bool acceptMediaRange)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
| Boolean | acceptMediaRange | If true, media ranges (i.e. strings of the form |
Returns
| Type | Description |
|---|---|
| String |
|
NotNull<T>(String, T)
Ensures that an argument is not null.
Declaration
public static T NotNull<T>(string argumentName, T value)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| T | value | The value to validate. |
Returns
| Type | Description |
|---|---|
| T |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the argument to validate. |
NotNullOrEmpty(String, String)
Ensures that a langword_csharp_string argument is neither null nor the empty string.
Declaration
public static string NotNullOrEmpty(string argumentName, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
Returns
| Type | Description |
|---|---|
| String |
|
Rfc2616Token(String, String, String)
Ensures that a langword_csharp_string argument is valid as a token as defined by RFC2616, Section 2.2.
RFC2616 tokens are used, for example, as:
- cookie names, as stated in RFC6265, Section 4.1.1;
- WebSocket protocol names, as stated in RFC6455, Section 4.3.
Only a restricted set of characters are allowed in tokens, including:
- upper- and lower-case letters of the English alphabet;
- decimal digits;
- the following non-alphanumeric characters:
!,#,$,%,&,',*,+,-,.,^,_,`,|,~.
Declaration
public static string Rfc2616Token(string argumentName, string value, string entity = "Token")
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
| String | entity | What is being validated. This string is put at the start of the exception
message when validation fails. Default is |
Returns
| Type | Description |
|---|---|
| String |
|
Route(String, String, Boolean)
Ensures that the value of an argument is a valid route.
Declaration
public static string Route(string argumentName, string value, bool isBaseRoute)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
| Boolean | isBaseRoute | true if the argument must be a base route; false if the argument must be a non-base route. |
Returns
| Type | Description |
|---|---|
| String |
|
See Also
Url(String, String, Uri, Boolean)
Ensures that a valid URL, either absolute or relative to the given baseUri,
can be constructed from a langword_csharp_string argument and returns the absolute URL
obtained by combining baseUri and value.
Declaration
public static string Url(string argumentName, string value, Uri baseUri, bool enforceHttp = false)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | Name of the argument. |
| String | value | The value. |
| Uri | baseUri | The base URI for relative URLs. |
| Boolean | enforceHttp | Ensure that the scheme of the resulting URL is either |
Returns
| Type | Description |
|---|---|
| String | The string representation of the constructed URL. |
See Also
Url(String, String, UriKind, Boolean)
Ensures that a valid URL can be constructed from a langword_csharp_string argument.
Declaration
public static string Url(string argumentName, string value, UriKind uriKind = null, bool enforceHttp = false)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | Name of the argument. |
| String | value | The value. |
| UriKind | uriKind | Specifies whether |
| Boolean | enforceHttp | Ensure that, if |
Returns
| Type | Description |
|---|---|
| String | The string representation of the constructed URL. |
See Also
UrlPath(String, String, Boolean)
Ensures that the value of an argument is a valid URL path and normalizes it.
Declaration
public static string UrlPath(string argumentName, string value, bool isBasePath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | argumentName | The name of the argument to validate. |
| String | value | The value to validate. |
| Boolean | isBasePath | If set to true |
Returns
| Type | Description |
|---|---|
| String | The normalized URL path. |