Exemplo n.º 1
0
        private AbcInstance DefineEnumSuperType(IType type)
        {
            if (!type.IsEnum)
            {
                throw new InvalidOperationException("type is not enum");
            }
            var vtype = type.ValueType;
            var st    = vtype.SystemType();

            if (st == null)
            {
                throw new InvalidOperationException(string.Format("invalid enum type {0}", type.FullName));
            }
            int index = GetEnumIndex(st);

            var instance = _enumSuperTypes[index];

            if (instance != null)
            {
                return(instance);
            }

            var super = BuildInstance(type.BaseType);

            instance = _enumSuperTypes[index];
            if (instance != null)
            {
                return(instance);
            }

            instance = new AbcInstance(true)
            {
                Name         = Abc.DefineName(QName.PfxPackage(GetEnumName(st))),
                BaseTypeName = super.Name,
                BaseInstance = super,
                Initializer  = Initializers.BuildDefaultInitializer(Abc, null)
            };
            Abc.AddInstance(instance);

            instance.Class.Initializer = Abc.DefineEmptyMethod();

            _enumSuperTypes[index] = instance;

            string name = Const.Boxing.Value;

            instance.CreateSlot(Abc.DefineName(QName.Global(name)), BuildMemberType(vtype));

            //SetFlags(instance, type);

            return(instance);
        }