Class Option
This class contains static methods for creation an Option<T>.
Inherited Members
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
public static class Option
Methods
| Edit this page View SourceBind<TKey, TValue>(TryGetValue<TKey, TValue>)
Generates a function that calls the provided TryGetValue<TKey, TValue> delegate and wraps the result as an Option<T>.
Declaration
public static Func<TKey, Option<TValue>> Bind<TKey, TValue>(TryGetValue<TKey, TValue> tryGetValue) where TKey : notnull where TValue : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| TryGetValue<TKey, TValue> | tryGetValue | The TryGetValue<TKey, TValue> function to call. |
Returns
| Type | Description |
|---|---|
| Func<TKey, Option<TValue>> | A function that will call the |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key. |
| TValue | The type to get. |
Create<T>(T?)
Returns a Some option for the specified value is it is not null, otherwise None.
Declaration
public static Option<T> Create<T>(T? value) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T? | value | The value to wrap in a |
Returns
| Type | Description |
|---|---|
| Option<T> | The given value, wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T |
Create<T>(T?)
Returns a Some option for the specified value if it is not null, otherwise None.
Declaration
public static Option<T> Create<T>(T? value) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to wrap in a |
Returns
| Type | Description |
|---|---|
| Option<T> | The given value, wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T |
None<T>()
Returns the None option for the specified T.
Declaration
public static Option<T> None<T>() where T : notnull
Returns
| Type | Description |
|---|---|
| Option<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
ParseEnum<T>(ReadOnlySpan<char>, bool)
Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return value indicates whether the conversion succeeded.
Declaration
public static Option<T> ParseEnum<T>(ReadOnlySpan<char> value, bool ignoreCase = false) where T : struct, Enum
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | value | The string to parse. |
| bool | ignoreCase | Whether to ignore case while parsing. Defaults to |
Returns
| Type | Description |
|---|---|
| Option<T> | An Option<T> containing the parsed enum, or |
Type Parameters
| Name | Description |
|---|---|
| T | The enum type to parse into. |
ParseEnum<T>(string, bool)
Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return value indicates whether the conversion succeeded.
Declaration
public static Option<T> ParseEnum<T>(string value, bool ignoreCase = false) where T : struct, Enum
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| bool | ignoreCase | Whether to ignore case while parsing. Defaults to |
Returns
| Type | Description |
|---|---|
| Option<T> | An Option<T> containing the parsed enum, or |
Type Parameters
| Name | Description |
|---|---|
| T | The enum type to parse into. |
Parse<T>(ReadOnlySpan<char>)
Parses a char span into any type that supports ISpanParsable<TSelf>.
Declaration
public static Option<T> Parse<T>(ReadOnlySpan<char> s) where T : ISpanParsable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | s | The char span to parse. |
Returns
| Type | Description |
|---|---|
| Option<T> | The parsed value wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T | The type to parse the char span into. |
Parse<T>(ReadOnlySpan<char>, IFormatProvider?)
Parses a char span into any type that supports ISpanParsable<TSelf>.
Declaration
public static Option<T> Parse<T>(ReadOnlySpan<char> s, IFormatProvider? provider) where T : ISpanParsable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | s | The char span to parse. |
| IFormatProvider | provider | An optional format provider. |
Returns
| Type | Description |
|---|---|
| Option<T> | The parsed value wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T | The type to parse the char span into. |
Parse<T>(string)
Parses a string into any type that supports IParsable<TSelf>.
Declaration
public static Option<T> Parse<T>(string s) where T : IParsable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to parse. |
Returns
| Type | Description |
|---|---|
| Option<T> | The parsed value wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T | The type to parse the string into. |
Parse<T>(string, IFormatProvider?)
Parses a string into any type that supports IParsable<TSelf>.
Declaration
public static Option<T> Parse<T>(string s, IFormatProvider? provider) where T : IParsable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to parse. |
| IFormatProvider | provider | An optional format provider. |
Returns
| Type | Description |
|---|---|
| Option<T> | The parsed value wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T | The type to parse the string into. |
Some<T>(T)
Returns a Some option for the specified value.
Declaration
public static Option<T> Some<T>(T value) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to wrap in a |
Returns
| Type | Description |
|---|---|
| Option<T> | The given value, wrapped in a |
Type Parameters
| Name | Description |
|---|---|
| T |
Try<T>(TryGet<T>)
Declaration
public static Option<T> Try<T>(TryGet<T> tryGet) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| TryGet<T> | tryGet | The TryGet<T> function to call. |
Returns
| Type | Description |
|---|---|
| Option<T> | A function that will call the |
Type Parameters
| Name | Description |
|---|---|
| T | The type to get. |