public void DeclareFieldsAndConstructor(BooClassBuilder builder) { var keys = _referencedEntities.Keys.Cast <ITypedEntity>().ToArray(); foreach (var entity in keys) { _collector.Visit(entity.Type); } if (_collector.Matches.Any()) { BuildTypeMap(builder.ClassDefinition); } // referenced entities turn into fields foreach (var entity in keys) { Field field = builder.AddInternalField(GetUniqueName(entity.Name), _mapper.MapType(entity.Type)); _referencedEntities[entity] = (InternalField)field.Entity; } // single constructor taking all referenced entities BooMethodBuilder constructor = builder.AddConstructor(); constructor.Modifiers = TypeMemberModifiers.Public; constructor.Body.Add(CodeBuilder.CreateSuperConstructorInvocation(builder.Entity.BaseType)); foreach (var entity in _referencedEntities.Keys) { InternalField field = _referencedEntities[entity]; ParameterDeclaration parameter = constructor.AddParameter(field.Name, ((ITypedEntity)entity).Type); constructor.Body.Add( CodeBuilder.CreateAssignment(CodeBuilder.CreateReference(field), CodeBuilder.CreateReference(parameter))); } }