根据EnumName获取Value

    /// 
    /// 根据EnumName获取Value 
    /// 
    /// 
    /// 
    /// 
    public static int GetEnumValue(Type enumType, string enumName)
    {
        try
        {
            if (!enumType.IsEnum)
                throw new ArgumentException("enumType必须是枚举类型");
            var values = Enum.GetValues(enumType);
            var ht = new Hashtable();
            foreach (var val in values)
            {
                ht.Add(Enum.GetName(enumType, val), val);
            }
            return (int)ht[enumName];
        }
        catch (Exception e)
        {
            throw e;
        }
    }

 

你可能感兴趣的:(Unity)