Show / Hide Table of Contents

Class Option

This class contains static methods for creation an Option<T>.

Inheritance
object
Option
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
public static class Option

Methods

| Edit this page View Source

Bind<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 tryGetValue function and wrap the results as an Option<T>.

Type Parameters
Name Description
TKey

The type of the key.

TValue

The type to get.

| Edit this page View Source

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 Some option.

Returns
Type Description
Option<T>

The given value, wrapped in a Some option.

Type Parameters
Name Description
T
| Edit this page View Source

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 Some option.

Returns
Type Description
Option<T>

The given value, wrapped in a Some option.

Type Parameters
Name Description
T
| Edit this page View Source

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
| Edit this page View Source

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 false.

Returns
Type Description
Option<T>

An Option<T> containing the parsed enum, or None.

Type Parameters
Name Description
T

The enum type to parse into.

| Edit this page View Source

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 false.

Returns
Type Description
Option<T>

An Option<T> containing the parsed enum, or None.

Type Parameters
Name Description
T

The enum type to parse into.

| Edit this page View Source

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 Some option, or else None.

Type Parameters
Name Description
T

The type to parse the char span into.

| Edit this page View Source

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 Some option, or else None.

Type Parameters
Name Description
T

The type to parse the char span into.

| Edit this page View Source

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 Some option, or else None.

Type Parameters
Name Description
T

The type to parse the string into.

| Edit this page View Source

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 Some option, or else None.

Type Parameters
Name Description
T

The type to parse the string into.

| Edit this page View Source

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 Some option.

Returns
Type Description
Option<T>

The given value, wrapped in a Some option.

Type Parameters
Name Description
T
| Edit this page View Source

Try<T>(TryGet<T>)

Calls the provided TryGet<T> delegate and wraps the result as an Option<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 tryGet function and wrap the results as an Option<T>.

Type Parameters
Name Description
T

The type to get.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX