SpanExtensionsToEnumTEnum Method
Tries to convert the specified
ReadOnlySpan<char> to an
Enum value of
TEnum type.
No string allocation occurs when using this method.
Namespace: KGySoft.CoreLibrariesAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.0.0
public static TEnum? ToEnum<TEnum>(
this ReadOnlySpan<char> s,
bool definedOnly = false
)
where TEnum : struct, new()
<ExtensionAttribute>
Public Shared Function ToEnum(Of TEnum As {Structure, New}) (
s As ReadOnlySpan(Of Char),
Optional definedOnly As Boolean = false
) As TEnum?
public:
[ExtensionAttribute]
generic<typename TEnum>
where TEnum : value class, gcnew()
static Nullable<TEnum> ToEnum(
ReadOnlySpan<wchar_t> s,
bool definedOnly = false
)
[<ExtensionAttribute>]
static member ToEnum :
s : ReadOnlySpan<char> *
?definedOnly : bool
(* Defaults:
let _definedOnly = defaultArg definedOnly false
*)
-> Nullable<'TEnum> when 'TEnum : struct, new()
- s ReadOnlySpanChar
- The ReadOnlySpan<char> to convert.
- definedOnly Boolean (Optional)
- If , the result can only be a defined value in the specified TEnum type.
If , the result can be a non-defined value, too.
- TEnum
- The type of the Enum.
NullableTEnumA non-
value if the conversion was successful; otherwise,
.In Visual Basic and C#, you can call this method as an instance method on any object of type
ReadOnlySpanChar. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).