mirror of
https://github.com/4sval/FModel.git
synced 2026-09-22 00:14:38 -05:00
enum cleanups
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using FModel.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using FModel.Properties;
|
||||
|
||||
namespace FModel.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
@@ -47,12 +48,12 @@ namespace FModel.Extensions
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T ToEnum<T>(this string value, T defaultValue)
|
||||
public static T ToEnum<T>(this string value, T defaultValue) where T : struct
|
||||
{
|
||||
if (!Enum.TryParse(typeof(T), value, true, out var ret))
|
||||
if (!Enum.TryParse(value, true, out T ret))
|
||||
return defaultValue;
|
||||
|
||||
return (T) ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -81,4 +82,4 @@ namespace FModel.Extensions
|
||||
return i == -1 ? (T) values.GetValue(values.Length - 1) : (T) values.GetValue(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user