예제 #1
0
    public static List <string> GenerateClass()
    {
        /*if (type.IsInterface)
         * {
         *  Debug.Log("Interface: " + type.ToString() + " ignored.");
         *  return;
         * }*/

        List <string> memberNames = new List <string>();

        GeneratorHelp.ATypeInfo ti;
        int slot         = GeneratorHelp.AddTypeInfo(type, out ti);
        var sbHeader     = BuildHeader(type);
        var sbCons       = sbHeader.Append(BuildConstructors(type, ti.constructors, slot, ti.howmanyConstructors, memberNames));
        var sbFields     = BuildFields(type, ti.fields, slot, memberNames);
        var sbProperties = BuildProperties(type, ti.properties, slot, memberNames);
        var sbMethods    = BuildMethods(type, ti.methods, slot, memberNames);
        //sbMethods.Append(BuildTail());
        var sbClass = BuildClass(type, sbFields, sbProperties, sbMethods, sbCons);

        HandleStringFormat(sbClass);


        //        string fileName = JSBindingSettings.jsGeneratedDir + "/" +
        //            JSNameMgr.GetTypeFileName(JSGenerator.type)
        //            + JSBindingSettings.jsExtension;
        //        var writer2 = OpenFile(fileName, false);
        //        writer2.Write(sbClass.ToString());
        //        writer2.Close();
        W.Write(sbClass.ToString());

        return(memberNames);
    }
예제 #2
0
    public static void GenerateClass(Type type, out List <string> memberNames)
    {
        memberNames = new List <string>();

        GeneratorHelp.ATypeInfo ti;
        int    slot      = GeneratorHelp.AddTypeInfo(type, out ti);
        string jsDefName = GetJsTypeDefinition(type);

        var sbClass = new StringBuilder();

        var sbDefinition       = new StringBuilder();
        var sbStaticDefinition = new StringBuilder();

        BuildConstructors(type, ti.constructors, slot, sbDefinition, memberNames);
        BuildProperties(type, ti.properties, slot, sbDefinition, sbStaticDefinition, memberNames);
        BuildMethods(type, ti.methods, slot, sbDefinition, sbStaticDefinition, memberNames);
        var sbAllDefinition = new StringBuilder();

        if (sbStaticDefinition.Length > 0)
        {
            sbAllDefinition.AppendFormat(@"
    staticDefinition: [[{0}
    ]],", sbStaticDefinition);
        }

        if (sbDefinition.Length > 0)
        {
            sbAllDefinition.AppendFormat(@"
    definition: [[{0}
    ]],", sbDefinition);
        }

        sbClass.AppendFormat(@"
// {0}
var {1} = 
[[
    assemblyName: '{2}',
    fullname: '{3}',
    Kind: '{4}',{5}{6}{7}
]];
jsb_ReplaceOrPushJsType({1});
", type.FullName, jsDefName, type.Assembly.FullName, JSNameMgr.GetJSTypeFullName(type),
                             GetJsTypeKind(type),
                             GetJsTypeInheritInfo(type),
                             BuildFields(type, ti.fields, slot, memberNames),
                             sbAllDefinition);
        HandleStringFormat(sbClass);

        _streamWriter.Write(sbClass.ToString());
    }