Table of Contents

Method TryParseDefinedEnum

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

TryParseDefinedEnum<TEnum>(string?)

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

[Pure]
public static Maybe<TEnum> TryParseDefinedEnum<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 if the enumeration declares it, and one containing no value otherwise.

Type Parameters

TEnum

The enumeration type to parse.

Remarks

TryParseEnum<TEnum>(string?) with one more check: the result must be a member that the enumeration declares. That is what keeps "37" from a parse to a value that no code handles. Use this one when the string came from out of the process. Not for an enumeration marked FlagsAttribute. A combination of declared flags is a good value, but the enumeration does not declare it. Thus, it gives no value here. Use TryParseEnum<TEnum>(string?) for those.

TryParseDefinedEnum<TEnum>(string?, bool)

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

[Pure]
public static Maybe<TEnum> TryParseDefinedEnum<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 if the enumeration declares it, and one containing no value otherwise.

Type Parameters

TEnum

The enumeration type to parse.

Remarks

Not for an enumeration marked FlagsAttribute. See TryParseDefinedEnum<TEnum>(string?).