Пример #1
0
        public EnumData(Type type)
        {
            EnumOverride data = type.GetCustomAttribute <EnumOverride>();

            CodeName = data?.CodeName ?? type.Name;

            Type           = type;
            UnderlyingType = Enum.GetUnderlyingType(type);

            var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);

            Members = new EnumMember[fields.Length];
            var values = Enum.GetValues(type);

            for (int v = 0; v < Members.Length; v++)
            {
                EnumOverride fieldData         = fields[v].GetCustomAttribute <EnumOverride>();
                string       fieldCodeName     = fieldData?.CodeName ?? fields[v].Name;
                string       fieldWorkshopName = fieldData?.WorkshopName ?? Extras.AddSpacesToSentence(fields[v].Name.Replace('_', ' '), false);
                string       i18nKeyword       = fieldData?.I18nKeyword ?? fieldWorkshopName;

                Members[v] = new EnumMember(this, fieldCodeName, fieldWorkshopName, values.GetValue(v))
                {
                    I18nKeyword = i18nKeyword
                };
            }
        }