📄 enumhelper.cs
字号:
namespace Imps.Utils
{
using System;
public static class EnumHelper
{
public static T Int32ToEnum<T>(int iVal, T defVal)
{
try
{
return (T) Enum.ToObject(typeof(T), iVal);
}
catch
{
return defVal;
}
}
public static T IntStrToEnum<T>(string strVal)
{
return IntStrToEnum<T>(strVal, default(T));
}
public static T IntStrToEnum<T>(string strVal, T defVal)
{
if (string.IsNullOrEmpty(strVal))
{
return defVal;
}
try
{
return (T) Enum.ToObject(typeof(T), Convert.ToInt32(strVal));
}
catch
{
return defVal;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -