IEnumerable <MemberDeclarationSyntax> TransformStruct(TypeDefinition def)
        {
            var topDecl = ClassDeclaration(_names.MakeTypeName(def).Identifier)
                          .AddModifiers(_names.TypeVisibilityModifier);

            if (_names.EmitDomainClassesAndInterfaces)
            {
                topDecl = topDecl.AddBaseListTypes(SimpleBaseType(_names.Type <Capnp.ICapnpSerializable>(Nullability.NonNullable)));
            }
            else
            {
                topDecl = topDecl.AddModifiers(Static);
            }


            if (def.GenericParameters.Count > 0)
            {
                topDecl = topDecl
                          .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray())
                          .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray());
            }

            topDecl = topDecl
                      .AddMembers(_names.MakeTypeIdConst(def.Id))
                      .AddAttributeLists(_names.MakeTypeDecorationAttributes(def.Id));

            if (def.UnionInfo != null)
            {
                topDecl = topDecl.AddMembers(_commonGen.MakeUnionSelectorEnum(def));
            }

            if (_names.EmitDomainClassesAndInterfaces)
            {
                topDecl = topDecl.AddMembers(_domClassGen.MakeDomainClassMembers(def));
            }

            topDecl = topDecl.AddMembers(
                _readerGen.MakeReaderStruct(def),
                _writerGen.MakeWriterStruct(def));

            foreach (var nestedGroup in def.NestedGroups)
            {
                topDecl = topDecl.AddMembers(Transform(nestedGroup).ToArray());
            }

            foreach (var nestedDef in def.NestedTypes)
            {
                topDecl = topDecl.AddMembers(Transform(nestedDef).ToArray());
            }

            yield return(topDecl);
        }
        IEnumerable <MemberDeclarationSyntax> TransformStruct(TypeDefinition def)
        {
            var topDecl = ClassDeclaration(_names.MakeTypeName(def).Identifier)
                          .AddModifiers(Public)
                          .AddBaseListTypes(SimpleBaseType(Type <Capnp.ICapnpSerializable>()));

            if (def.GenericParameters.Count > 0)
            {
                topDecl = topDecl
                          .AddTypeParameterListParameters(MakeTypeParameters(def).ToArray())
                          .AddConstraintClauses(MakeTypeParameterConstraints(def).ToArray());
            }

            topDecl = topDecl.AddMembers(CommonSnippetGen.MakeTypeIdConst(def.Id, _names));
            topDecl = topDecl.WithAttributeLists(CommonSnippetGen.MakeTypeIdAttributeLists(def.Id));

            if (def.UnionInfo != null)
            {
                topDecl = topDecl.AddMembers(_commonGen.MakeUnionSelectorEnum(def));
            }

            topDecl = topDecl.AddMembers(_domClassGen.MakeDomainClassMembers(def));
            topDecl = topDecl.AddMembers(_readerGen.MakeReaderStruct(def));
            topDecl = topDecl.AddMembers(_writerGen.MakeWriterStruct(def));

            foreach (var nestedGroup in def.NestedGroups)
            {
                topDecl = topDecl.AddMembers(Transform(nestedGroup).ToArray());
            }

            foreach (var nestedDef in def.NestedTypes)
            {
                topDecl = topDecl.AddMembers(Transform(nestedDef).ToArray());
            }

            yield return(topDecl);
        }