26 lines
645 B
C#
26 lines
645 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Yi.Framework.Infrastructure.Helper
|
|
{
|
|
public static class EnumHelper
|
|
{
|
|
public static New EnumToEnum<New>(this object oldEnum)
|
|
{
|
|
if (oldEnum is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(oldEnum));
|
|
}
|
|
return (New)Enum.ToObject(typeof(New), oldEnum.GetHashCode());
|
|
}
|
|
|
|
public static TEnum StringToEnum<TEnum>(this string str)
|
|
{
|
|
return (TEnum)Enum.Parse(typeof(TEnum), str);
|
|
}
|
|
}
|
|
}
|