Exemplo n.º 1
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool TryKeyword(Type enumType, object Value, out string outKeyword)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            if (Value is null)
            {
                throw new ArgumentNullException(nameof(Value));
            }
            Contract.EndContractBlock();

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

            if (enumIndex < 0)
            {
                /* Enum has no index */
                outKeyword = null;
                return(false);
            }

            /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
            //outKeyword = EnumMetaTable.Get(enumIndex, CastTo<int>.From(Value)).Keyword;
            outKeyword = EnumMetaTable.Get(enumIndex, CastTo <int> .From(Value)).Keyword;
            return(true);
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool TryData <T>(T Value, out EnumData outData) where T : struct
        {
            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex < 0)
            {
                /* Enum has no index */
                outData = default;
                return(false);
            }

            /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
            outData = EnumMetaTable.Get(enumIndex, CastTo <int> .From(Value));
            return(true);
        }
Exemplo n.º 4
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static string Keyword <T>(T Value) where T : struct
        {
            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex > -1)
            {
                /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
                string keyword = EnumMetaTable.Get(enumIndex, CastTo <int> .From(Value)).Keyword;
                if (keyword is object)
                {
                    return(keyword);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {System.Enum.GetName(typeof(T), Value)} in meta-enum table");
        }
Exemplo n.º 5
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static bool TryKeyword <T>(T Value, out string outKeyword) where T : struct
        {
            int enumIndex = EnumMetaTable.Meta.Lookup <T>();

            if (enumIndex < 0)
            {
                /* Enum has no index */
                outKeyword = null;
                return(false);
            }

            /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
            //outKeyword = EnumMetaTable.Get(enumIndex, CastTo<int>.From(Value)).Keyword;
            outKeyword = EnumMetaTable.Get(enumIndex, CastTo <int> .From(Value)).Keyword;
            return(true);
        }
Exemplo n.º 6
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)]// Small function which is called frequently in loops, inline it
        public static string Keyword(Type enumType, object Value)
        {
            if (enumType is null)
            {
                throw new ArgumentNullException(nameof(enumType));
            }
            Contract.EndContractBlock();

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

            if (enumIndex > -1)
            {
                /* /!\ This conversion will f*****g EXPLODE if the given generic type does not have an integer backing type /!\ */
                string keyword = EnumMetaTable.Get(enumIndex, CastTo <int> .From(Value)).Keyword;
                if (keyword is object)
                {
                    return(keyword);
                }
            }

            throw new Exception($"Unable to find keyword for enum value {System.Enum.GetName(enumType, Value)} in meta-enum table");
        }
Exemplo n.º 7
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");
        }