Class StringDecoratorExtensions
Extension methods for the String class tailored to adhere the decorator pattern.
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class StringDecoratorExtensions
Methods
| Improve this Doc View SourceStartsWith(IDecorator<String>, IEnumerable<String>)
Determines whether the beginning of the enclosed String of the specified decorator
matches at least one string in the specified sequence of strings
.
Declaration
public static bool StartsWith(this IDecorator<string> decorator, IEnumerable<string> strings)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
IEnumerable<String> | strings | A sequence of String values to match against. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
This match is performed by using a default value of OrdinalIgnoreCase.
StartsWith(IDecorator<String>, String[])
Determines whether the beginning of the enclosed String of the specified decorator
matches at least one string in the specified sequence of strings
.
Declaration
public static bool StartsWith(this IDecorator<string> decorator, params string[] strings)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
String[] | strings | A sequence of String values to match against. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
This match is performed by using a default value of OrdinalIgnoreCase.
StartsWith(IDecorator<String>, StringComparison, IEnumerable<String>)
Determines whether the beginning of the enclosed String of the specified decorator
matches at least one string in the specified sequence of strings
.
Declaration
public static bool StartsWith(this IDecorator<string> decorator, StringComparison comparison, IEnumerable<string> strings)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
IEnumerable<String> | strings | A sequence of String values to match against. |
Returns
Type | Description |
---|---|
Boolean |
|
StartsWith(IDecorator<String>, StringComparison, String[])
Determines whether the beginning of the enclosed String of the specified decorator
matches at least one string in the specified sequence of strings
.
Declaration
public static bool StartsWith(this IDecorator<string> decorator, StringComparison comparison, params string[] strings)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
StringComparison | comparison | One of the enumeration values that specifies the rules to use in the comparison. |
String[] | strings | A sequence of String values to match against. |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
This match is performed by using a default value of OrdinalIgnoreCase.
ToAsciiEncodedString(IDecorator<String>, Action<EncodingOptions>)
Encodes all the characters in the enclosed String of the specified decorator
to its ASCII encoded variant.
Declaration
public static string ToAsciiEncodedString(this IDecorator<string> decorator, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
Action<EncodingOptions> | setup | The EncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
String | A String variant of the enclosed String of the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ToByteArray(IDecorator<String>, Action<EncodingOptions>)
Converts the enclosed String of the specified decorator
to its equivalent byte[] representation.
Declaration
public static byte[] ToByteArray(this IDecorator<string> decorator, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
Action<EncodingOptions> | setup | The EncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] containing the result of the enclosed String of the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidEnumArgumentException |
|
ToCasing(IDecorator<String>, CasingMethod)
Converts the enclosed String of the specified decorator
to either lowercase, UPPERCASE, Title Case or unaltered.
Declaration
public static string ToCasing(this IDecorator<string> decorator, CasingMethod method = CasingMethod.Default)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
CasingMethod | method | The method to use in the conversion. |
Returns
Type | Description |
---|---|
String | A String that corresponds to the enclosed String of the specified |
Remarks
Uses InvariantCulture for the conversion.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ToCasing(IDecorator<String>, CasingMethod, CultureInfo)
Converts the enclosed String of the specified decorator
to either lowercase, UPPERCASE, Title Case or unaltered using the specified culture
.
Declaration
public static string ToCasing(this IDecorator<string> decorator, CasingMethod method, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
CasingMethod | method | The method to use in the conversion. |
CultureInfo | culture | The culture rules to apply the conversion. |
Returns
Type | Description |
---|---|
String | A String that corresponds to the enclosed String of the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ToEncodedString(IDecorator<String>, Action<FallbackEncodingOptions>)
Encodes all the characters in the enclosed String of the specified decorator
to its encoded String variant.
Declaration
public static string ToEncodedString(this IDecorator<string> decorator, Action<FallbackEncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
Action<FallbackEncodingOptions> | setup | The FallbackEncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
String | A String variant of the enclosed String of the specified |
Remarks
The inspiration for this method was retrieved @ SO: https://stackoverflow.com/a/135473/175073.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ToStream(IDecorator<String>, Action<EncodingOptions>)
Declaration
public static Stream ToStream(this IDecorator<string> decorator, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
Action<EncodingOptions> | setup | The EncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
Stream | A Stream containing the result of the enclosed String of the specified |
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidEnumArgumentException |
|
ToStreamAsync(IDecorator<String>, Action<AsyncEncodingOptions>)
Declaration
public static Task<Stream> ToStreamAsync(this IDecorator<string> decorator, Action<AsyncEncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
Action<AsyncEncodingOptions> | setup | The AsyncEncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
Task<Stream> | A task that represents the asynchronous operation. The task result contains a Stream containing the result of the enclosed String of the specified |
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidEnumArgumentException |
|
ToUri(IDecorator<String>, UriKind)
Declaration
public static Uri ToUri(this IDecorator<string> decorator, UriKind uriKind = UriKind.Absolute)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<String> | decorator | The IDecorator<T> to extend. |
UriKind | uriKind | Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate. |
Returns
Type | Description |
---|---|
Uri | A Uri that corresponds to the enclosed String of the specified |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentNullException | The enclosed String of the specified |
ArgumentException | The enclosed String of the specified |