예제 #1
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static EnumData Data(Type enumType, object Value)
        {
            /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            int vIdx = CastTo <int> .From(Value);

            if (vIdx < 0)
            {
                throw new IndexOutOfRangeException();
            }
            Contract.EndContractBlock();

            int enumIndex = EnumMetaTable.Meta.Lookup(enumType.TypeHandle);

            if (enumIndex > -1)
            {
                if (vIdx > 0 && vIdx < EnumMetaTable.Count(enumIndex))
                {
                    var dataLookup = EnumMetaTable.Get(enumIndex, vIdx);
                    return(dataLookup);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {System.Enum.GetName(enumType, Value)} in meta-enum table");
        }
예제 #2
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static EnumData Data <T>(T Value) where T : struct
        {
            /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
            int vIdx = CastTo <int> .From(Value);

            if (vIdx < 0)
            {
                throw new IndexOutOfRangeException();
            }
            Contract.EndContractBlock();

            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex > -1)
            {
                if (vIdx > 0 && vIdx < EnumMetaTable.Count(enumIndex))
                {
                    var dataLookup = EnumMetaTable.Get(enumIndex, vIdx);
                    return(dataLookup);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {System.Enum.GetName(typeof(T), Value)} in meta-enum table");
        }