Exemple #1
0
        public void DeclareFieldsAndConstructor(BooClassBuilder builder)
        {
            // referenced entities turn into fields
            foreach (ITypedEntity entity in Builtins.array(_referencedEntities.Keys))
            {
                Field field = builder.AddField("__" + entity.Name + _context.AllocIndex(), entity.Type);
                field.Modifiers             = TypeMemberModifiers.Internal;
                _referencedEntities[entity] = field.Entity;
            }

            // single constructor taking all referenced entities
            BooMethodBuilder constructor = builder.AddConstructor();

            constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType));
            foreach (ITypedEntity entity in _referencedEntities.Keys)
            {
                InternalField        field     = (InternalField)_referencedEntities[entity];
                ParameterDeclaration parameter = constructor.AddParameter(field.Name, entity.Type);
                constructor.Body.Add(
                    CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field),
                                                 CodeBuilder.CreateReference(parameter)));
            }
        }