public void RoundTripStruct()
        {
            ModuleDeclaration module   = ReflectToModules("public struct Foo {\npublic var x:Int\n } ", "SomeModule").Find(m => m.Name == "SomeModule");
            StructDeclaration fooClass = module.AllStructs.Where(cl => cl.Name == "Foo").FirstOrDefault();

            Assert.IsNotNull(fooClass);
            StructDeclaration unrootedFoo = fooClass.MakeUnrooted() as StructDeclaration;

            Entity entity = new Entity {
                SharpNamespace = "SomeModule",
                SharpTypeName  = "Foo",
                Type           = unrootedFoo
            };

            TypeDatabase db = new TypeDatabase();

            db.Add(entity);

            MemoryStream ostm = new MemoryStream();

            db.Write(ostm, "SomeModule");
            ostm.Seek(0, SeekOrigin.Begin);

            TypeDatabase dbread = new TypeDatabase();
            var          errors = dbread.Read(ostm);

            Utils.CheckErrors(errors);
            Entity entityRead = dbread.EntityForSwiftName("SomeModule.Foo");

            Assert.IsNotNull(entityRead);
            Assert.AreEqual(entity.SharpNamespace, entityRead.SharpNamespace);
            Assert.AreEqual(entity.SharpTypeName, entityRead.SharpTypeName);
            Assert.IsTrue(entity.Type is StructDeclaration);
        }
        TypeDeclaration ToStructDeclaration(TypeDefinition definition)
        {
            var name       = TypeAggregator.ProtocolAttributeName(definition) ?? definition.Name;
            var moduleName = definition.Namespace;

            if (TypeAggregator.FilterModuleAndName(platform, moduleName, ref name))
            {
                TypeAggregator.RemapModuleAndName(platform, ref moduleName, ref name, TypeType.Struct);
                var module            = ToModuleDeclaration(moduleName);
                var structDeclaration = new StructDeclaration {
                    Name            = name,
                    Access          = ToAccessibility(definition),
                    Module          = module,
                    ParentExtension = null,
                    Kind            = TypeKind.Struct,
                    Members         = new List <Member> (),
                    IsObjC          = true,
                    IsFinal         = true,
                    IsDeprecated    = false,
                    IsUnavailable   = false
                };
                return(structDeclaration.MakeUnrooted());
            }
            return(null);
        }