Ejemplo n.º 1
0
        static EnumInfo CreateEnumInfo(DmdType type)
        {
            bool hasFlagsAttribute = type.IsDefined("System.FlagsAttribute", inherit: false);
            var  fields            = type.DeclaredFields;
            int  count             = fields.Count - 1;

            if (count <= 0)
            {
                return(new EnumInfo(hasFlagsAttribute, Array.Empty <EnumFieldInfo>()));
            }

            EnumFieldInfo[]? infos = new EnumFieldInfo[count];
            int w = 0;

            for (int i = 0; i < fields.Count; i++)
            {
                var field = fields[i];
                if (!field.IsLiteral || !field.IsStatic)
                {
                    continue;
                }
                if (!NumberUtils.TryConvertIntegerToUInt64ZeroExtend(field.GetRawConstantValue(), out var value))
                {
                    continue;
                }
                if (w >= infos.Length)
                {
                    Array.Resize(ref infos, w + 1);
                }
                infos ![w++] = new EnumFieldInfo(field, value);