private static void RegisterSimpleEnum(Type enumType, RuntimeEnvironment environment)
        {
            var enumTypeAttribute = (EnumerationTypeAttribute)enumType.GetCustomAttributes(typeof(EnumerationTypeAttribute), false)[0];

            var type = TypeManager.RegisterType("Перечисление" + enumTypeAttribute.Name, typeof(EnumerationContext));

            if (enumTypeAttribute.Alias != null)
            {
                TypeManager.RegisterAliasFor(type, "Enum" + enumTypeAttribute.Alias);
            }

            var enumValueType = TypeManager.RegisterType(enumTypeAttribute.Name, enumType);

            var instance = new EnumerationContext(type, enumValueType);

            var wrapperTypeUndefined = typeof(CLREnumValueWrapper <>);
            var wrapperType          = wrapperTypeUndefined.MakeGenericType(new Type [] { enumType });
            var constructor          = wrapperType.GetConstructor(new Type [] { typeof(EnumerationContext), enumType, typeof(DataType) });

            foreach (var field in enumType.GetFields())
            {
                foreach (var contextFieldAttribute in field.GetCustomAttributes(typeof(EnumItemAttribute), false))
                {
                    var contextField = (EnumItemAttribute)contextFieldAttribute;
                    var osValue      = (EnumerationValue)constructor.Invoke(new object [] { instance, field.GetValue(null), DataType.Enumeration });

                    if (contextField.Alias == null)
                    {
                        if (StringComparer
                            .InvariantCultureIgnoreCase
                            .Compare(field.Name, contextField.Name) != 0)
                        {
                            instance.AddValue(contextField.Name, field.Name, osValue);
                        }
                        else
                        {
                            instance.AddValue(contextField.Name, osValue);
                        }
                    }
                    else
                    {
                        instance.AddValue(contextField.Name, contextField.Alias, osValue);
                    }
                }
            }

            if (enumTypeAttribute.CreateGlobalProperty)
            {
                GlobalsManager.RegisterInstance(enumType, instance);
                environment.InjectGlobalProperty(instance, enumTypeAttribute.Name, true);
                if (enumTypeAttribute.Alias != null)
                {
                    environment.InjectGlobalProperty(instance, enumTypeAttribute.Alias, true);
                }
            }
        }
 public EnumerationValue(EnumerationContext owner)
 {
     _owner = owner;
 }
Example #3
0
 public EnumerationValue(EnumerationContext owner)
 {
     _owner = owner;
 }
Example #4
0
 public SymbolsEnumValue(EnumerationContext owner, string val)
     : base(owner)
 {
     _val = val;
 }
Example #5
0
 public CLREnumValueWrapper(EnumerationContext owner, T realValue, DataType newDataType) : base(owner)
 {
     _realValue         = realValue;
     _redefinedDataType = newDataType;
 }
Example #6
0
 public SelfAwareEnumValue(EnumerationContext owner) : base(owner)
 {
 }