添加Enum转换为Option的扩展
This commit is contained in:
parent
01633d1c4c
commit
83cc3df7aa
|
@ -0,0 +1,12 @@
|
|||
using Sanchime.Functional.Core.Products;
|
||||
|
||||
namespace Sanchime.Functional.Core.Extensions;
|
||||
|
||||
public static class EnumExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 将字符串转换为相应的枚举值的<see cref="Option"/
|
||||
/// </summary>
|
||||
public static Option<T> Parse<T>(this string @this) where T : struct
|
||||
=> Enum.TryParse(@this, out T val) ? Option.Some(val) : Option.None;
|
||||
}
|
Loading…
Reference in New Issue