enumhelper.cs

来自「破解的飞信源代码」· CS 代码 · 共 42 行

CS
42
字号
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 + =
减小字号Ctrl + -
显示快捷键?