/// <summary>
        /// Generates the type.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="cppTypename"></param>
        protected override void GenerateType(SourceWriter writer, string cppTypename)
        {
            writer.WriteLine("/**");
            writer.WriteLine(" * Type {0}", cppTypename);
            writer.WriteLine(" */");
            writer.WriteLine("struct {0}", cppTypename);
            writer.OpenBlock();
            {
                FieldInfo[] fields =
                    Type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                foreach (FieldInfo fieldInfo in fields)
                {
                    WriteField(writer, fieldInfo);
                }
            }
            writer.CloseBlock(";");
            writer.WriteLine();

            var attribute = Type.GetAttribute<CppValueObjectAttribute>(true);

            if (attribute.IsDescriptor)
            {
                writer.WriteLine("{0} descriptor_of_{1}(InvHandle handle);",
                                 cppTypename,
                                 (attribute.Typename ?? Type.Name.Replace("Descriptor", string.Empty)).ToLower());
                writer.WriteLine();
            }
        }
        /// <summary>
        /// Generates this instance.
        /// </summary>
        /// <returns></returns>
        protected override void GenerateType(SourceWriter writer, string cppTypename)
        {
            writer.WriteLine("/**");
            writer.WriteLine(" * Type {0}", cppTypename);
            writer.WriteLine(" */");
            writer.WriteLine("struct {0}", cppTypename);
            writer.OpenBlock();

            WriteBaseDescriptorField(writer);
            WriteDescriptorFields(writer);

            writer.CloseBlock(";");
            writer.WriteLine();
        }
        /// <summary>
        /// Generates this instance.
        /// </summary>
        /// <returns></returns>
        public string Generate()
        {
            string cppTypename = GetTypename();
            string filename = ConfigOptions.AdditionalInclude(cppTypename);
            string fullFilename = Path.Combine(ConfigOptions.CppOutputDir, filename);

            using (var writer = new SourceWriter(fullFilename))
            {
                string deffilename = string.Format("__{0}__", filename.Replace('.', '_').ToUpper());

                writer.WriteLine("#ifndef {0}", deffilename);
                writer.WriteLine("#define {0}", deffilename);
                writer.WriteLine();
                writer.WriteLine("#include <InvisionHandle.h>");

                foreach (string include in ScanIncludes())
                {
                    writer.WriteLine("#include \"{0}\"", include);
                }

                writer.WriteLine("#include \"{0}\"", ConfigOptions.IncludeCppHeader);
                writer.WriteLine();

                writer.WriteLine("extern \"C\"");
                writer.OpenBlock();
                {
                    GenerateType(writer, cppTypename);
                }
                writer.CloseBlock();
                writer.WriteLine();
                writer.WriteLine("#endif // {0}", deffilename);
                writer.WriteLine();
            }

            return filename;
        }