Table of Contents

Method TryParseEnum

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

TryParseEnum<TEnum>(string?)

Parses a value of the given enumeration type from this string, if it holds one.

[Pure]
public static Maybe<TEnum> TryParseEnum<TEnum>(this string? value) where TEnum : struct

Parameters

value string

The string to parse. A null string gives no value.

Returns

Maybe<TEnum>

A Maybe<T> containing the parsed value, and one containing no value if value does not hold one.

Type Parameters

TEnum

The enumeration type to parse.

Remarks

Wraps TryParse<TEnum>(string, out TEnum), and inherits its two surprises. Matching is case-sensitive, which TryParseEnum<TEnum>(string?, bool) can disable. More important is that a string of digits parses to that number when the enumeration does not declare it. Thus, "37" succeeds for an enumeration with three members. Use TryParseDefinedEnum<TEnum>(string?) where only a declared member is correct.

TryParseEnum<TEnum>(string?, bool)

Parses a value of the given enumeration type from this string, if it holds one, The compare can be case-insensitive.

[Pure]
public static Maybe<TEnum> TryParseEnum<TEnum>(this string? value, bool ignoreCase) where TEnum : struct

Parameters

value string

The string to parse. A null string gives no value.

ignoreCase bool

True for a case-insensitive compare of the member names.

Returns

Maybe<TEnum>

A Maybe<T> containing the parsed value, and one containing no value if value does not hold one.

Type Parameters

TEnum

The enumeration type to parse.

Remarks

Wraps TryParse<TEnum>(string, bool, out TEnum). A string of digits parses to that number, and it makes no difference if the enumeration declares it. See TryParseDefinedEnum<TEnum>(string?, bool).