static void WriteStructWithFields(CodeOutput codeOutput, ClosureEntities crRuntime, Type type)
        {
            if (DelegateManager.IsTypeDelegate(type))
                return;

            var mappedType = type.GetMappedType(crRuntime);
            type = mappedType.GetReversedMappedType(crRuntime);

            if (!type.IsValueType && type.BaseType != null)
            {
                //Not Necessary
                // codeOutput.AppendFormat("struct {0} : public {1} {2} {{", type.ToCppMangling(), type.BaseType.ToCppMangling(),type.GetInterfaces().Any()? " ,"+type.GetInterfaces().Select(j=>j.ToCppMangling()).Aggregate((a,b)=>a + " , " + b):"");
                codeOutput.AppendFormat(
                    "struct {0} : public {1}",
                    type.ToCppMangling(),
                    type.BaseType.ToCppMangling())
                    .BracketOpen();
            }
            else if (!type.IsValueType && type.IsInterface)
            {
                codeOutput.AppendFormat("struct {0} : public {1}",
                    type.ToCppMangling(),
                    typeof(object).ToCppMangling())
                    .BracketOpen();
            }
            else
            {
                codeOutput.AppendFormat("struct {0}", type.ToCppMangling())
                    .BracketOpen();
            }

            if (type == typeof(object))
            {
                codeOutput.Append("int _typeId;\n");
            }

            //String Support
            if (type == typeof(string))
            {
                crRuntime.AddType(typeof(string));
                var usedTypes = crRuntime.MappedTypes.Values.ToList();
                var typeTable = new TypeDescriptionTable(usedTypes, crRuntime);

                codeOutput.Append("System_String()")
                    .BracketOpen()
                    .AppendFormat("_typeId = {0};\n", typeTable.GetTypeId(typeof(string)))
                    .BracketClose()
                    .BlankLine();
            }

            WriteClassFieldsBody(codeOutput, mappedType, crRuntime);
            codeOutput.BracketClose(true)
                .Append(";\n")
                .BlankLine();

            var typedesc = UsedTypeList.Set(type, crRuntime);
            typedesc.WriteStaticFieldInitialization(codeOutput);
        }
        private static void WriteClosureStructBodies(Type[] typeDatas, StringBuilder sb, CrRuntimeLibrary crRuntime)
        {
            foreach (var typeData in typeDatas)
            {
                var mappedType = typeData.GetMappedType();
                if (!mappedType.IsGenericType)
                {
                    sb.AppendFormat("struct {0}; ", mappedType.ToCppMangling()).AppendLine();
                }
            }
            foreach (var typeData in typeDatas)
            {
                if (DelegateManager.IsTypeDelegate(typeData))
                {
                    continue;
                }
                var type       = typeData.GetMappedType();
                var mappedType = typeData;

                if (mappedType.IsGenericType)
                {
                    var genericTypeCount = mappedType.GetGenericArguments().Length;
                    var typeNames        = new List <string>();
                    for (var i = 1; i <= genericTypeCount; i++)
                    {
                        typeNames.Add("class T" + i);
                    }
                    sb.AppendFormat("template <{0}> ", string.Join(", ", typeNames)).AppendLine();
                }
                if (!type.IsValueType && type.BaseType != null)
                {
                    sb.AppendFormat("struct {0} : public {1} {{", type.ToCppMangling(), type.BaseType.ToCppMangling());
                }
                else
                {
                    sb.AppendFormat("struct {0} {{", type.ToCppMangling());
                }
                sb.AppendLine();
                if (type == typeof(object))
                {
                    sb.AppendLine("int _typeId;");
                }
                WriteClassFieldsBody(sb, mappedType, crRuntime);
                sb.AppendFormat("}};").AppendLine();

                var typedesc = UsedTypeList.Set(type, crRuntime);
                typedesc.WriteStaticFieldInitialization(sb);
            }
        }
        private static void WriteStructWithFields(StringBuilder sb, ClosureEntities crRuntime, Type type)
        {
            if (DelegateManager.IsTypeDelegate(type))
            {
                return;
            }
            var mappedType = type.GetMappedType(crRuntime);

            type = mappedType.GetReversedMappedType(crRuntime);

            if (!type.IsValueType && type.BaseType != null)
            {
                //Not Necessary
                // sb.AppendFormat("struct {0} : public {1} {2} {{", type.ToCppMangling(), type.BaseType.ToCppMangling(),type.GetInterfaces().Any()? " ,"+type.GetInterfaces().Select(j=>j.ToCppMangling()).Aggregate((a,b)=>a + " , " + b):"");
                sb.AppendFormat("struct {0} : public {1} {{", type.ToCppMangling(), type.BaseType.ToCppMangling());
            }
            else if (!type.IsValueType && type.IsInterface)
            {
                sb.AppendFormat("struct {0} : public {1} {{", type.ToCppMangling(), typeof(object).ToCppMangling());
            }
            else
            {
                sb.AppendFormat("struct {0} {{", type.ToCppMangling());
            }
            sb.AppendLine();
            if (type == typeof(object))
            {
                sb.AppendLine("int _typeId;");
            }
            //String Support
            if (type == typeof(string))
            {
                crRuntime.AddType(typeof(string));
                List <Type> usedTypes = crRuntime.MappedTypes.Values.ToList();
                var         typeTable = new TypeDescriptionTable(usedTypes, crRuntime);
                sb.AppendLine(String.Format("System_String() {{_typeId = {0}; }}", typeTable.GetTypeId(typeof(string))));
            }
            WriteClassFieldsBody(sb, mappedType, crRuntime);
            sb.AppendFormat("}};").AppendLine();

            var typedesc = UsedTypeList.Set(type, crRuntime);

            typedesc.WriteStaticFieldInitialization(sb);
        }