Esempio n. 1
0
        public override bool Equals(object obj)
        {
            BatchInfo b = obj as BatchInfo;

            return(b != null && this.name.Equals(b.name));
        }
Esempio n. 2
0
        void GenCode_CS_Mgr(CodeGenerator gen, BatchInfo batch)
        {
            if (batch == null)
            {
                gen.Line("namespace zf.util");
                gen.AddIndent("{");
                gen.Line("public partial class TemplateManager");
            }
            else
            {
                gen.Line("public class {0}", "Gen_" + batch.name);
            }
            gen.AddIndent("{");
            // Function CreateTemplate
            if (batch == null)
            {
                gen.Line("static partial void CreateTemplate_Inner(uint typeId, ref BaseTemplate ret)");
            }
            else
            {
                gen.Line("public static void CreateTemplate(uint typeId, ref BaseTemplate ret)");
            }
            gen.AddIndent("{");
            gen.Line("switch (typeId)");
            gen.AddIndent("{");

            foreach (var tp in this.mTypeList)
            {
                if ((tp.batch == null && batch == null) || (tp.batch != null && tp.batch.Equals(batch)))
                {
                    if (tp.CompileTo == CompileTarget.CSharp)
                    {
                        if (tp.IsClass())
                        {
                            GTypeClass classTp = tp as GTypeClass;
                            if (classTp.isTemplateClass)
                            {
                                gen.Line("case {0}.TYPE: ret = new {0}(); break;", tp.FullName);
                            }
                        }
                    }
                }
            }
            gen.Line("default:");
            gen.AddIndent();
            //gen.Line("GBGenLog.LogError(\"Can't find template type id: \" + typeId);");
            gen.Line("break;");
            gen.RemIndent();
            gen.RemIndent("}");
            gen.RemIndent("}");

            // Function CreateObject
            if (batch == null)
            {
                gen.Line("static partial void CreateObject_Inner(uint typeId, TID tid, ref BaseObject ret)");
            }
            else
            {
                gen.Line("public static void CreateObject(uint typeId, TID tid, ref BaseObject ret)");
            }
            gen.AddIndent("{");
            gen.Line("switch (typeId)");
            gen.AddIndent("{");

            foreach (var tp in this.mTypeList)
            {
                if ((tp.batch == null && batch == null) || (tp.batch != null && tp.batch.Equals(batch)))
                {
                    if (tp.CompileTo == CompileTarget.CSharp)
                    {
                        if (tp.IsClass())
                        {
                            GTypeClass classTp = tp as GTypeClass;
                            if (!string.IsNullOrEmpty(classTp.BindingClass))
                            {
                                if (!string.IsNullOrEmpty(classTp.BindingClassMacro))
                                {
                                    gen.Line("#if {0}", classTp.BindingClassMacro);
                                }

                                gen.Line("case {0}.TYPE: ret = new {1}(); break;", tp.Name, classTp.BindingClass);

                                if (!string.IsNullOrEmpty(classTp.BindingClassMacro))
                                {
                                    gen.Line("#endif");
                                }
                            }
                        }
                    }
                }
            }
            gen.Line("default:");
            gen.AddIndent();
            //gen.Line("GBGenLog.LogError(\"BindingClass is not defiend! type: \" + typeId);");
            gen.Line("break;");
            gen.RemIndent();
            gen.RemIndent("}");
            gen.RemIndent("}");
            gen.RemIndent("}");

            if (batch == null)
            {
                gen.RemIndent("}");
            }
        }
Esempio n. 3
0
        public bool GenCode_CS_Binding(out string code, BatchInfo batch)
        {
            StringWriter  writer = new StringWriter();
            CodeGenerator gen    = new CodeGenerator(writer);

            gen.Line("// ============================================================================================= //");
            gen.Line("// This is generated by tool. Don't edit this manually.");
            gen.Line("// Encoding: " + writer.Encoding.EncodingName);
            gen.Line("// ============================================================================================= //");
            gen.Line();
            gen.Line();
            gen.Line("using System.IO;");
            gen.Line("using zf.util;");
            gen.Line();
            gen.Line("#pragma warning disable 0108");
            gen.Line();

            // classes
            foreach (var tp in mTypeList)
            {
                if ((tp.batch == null && batch == null) || (tp.batch != null && tp.batch.Equals(batch)))
                {
                    if (tp.CompileTo == CompileTarget.CSharp)
                    {
                        if (tp.IsClass())
                        {
                            GTypeClass classTp = tp as GTypeClass;
                            if (!string.IsNullOrEmpty(classTp.BindingClass))
                            {
                                string spaceName     = null;
                                string bindclassName = null;
                                if (classTp.BindingClass.Contains("."))
                                {
                                    bindclassName = classTp.BindingClass.Substring(classTp.BindingClass.LastIndexOf('.') + 1);
                                    spaceName     = classTp.BindingClass.Substring(0, classTp.BindingClass.LastIndexOf('.'));
                                }
                                else
                                {
                                    bindclassName = classTp.BindingClass;
                                }

                                if (!string.IsNullOrEmpty(classTp.BindingClassMacro))
                                {
                                    gen.Line("#if {0}", classTp.BindingClassMacro);
                                }

                                if (!string.IsNullOrEmpty(spaceName))
                                {
                                    gen.Line("namespace {0}", spaceName);
                                    gen.AddIndent("{");
                                }
                                gen.Line("public partial class {0}", bindclassName);
                                gen.AddIndent("{");
                                gen.Line("public {0} template;", tp.Name);
                                gen.Line("public override void InitTemplate(BaseTemplate tmpl)");
                                gen.AddIndent("{");
                                gen.Line("base.InitTemplate(tmpl);");
                                gen.Line("template = tmpl as {0};", tp.Name);
                                gen.RemIndent("}");
                                gen.RemIndent("}");
                                if (!string.IsNullOrEmpty(spaceName))
                                {
                                    gen.RemIndent("}");
                                }

                                if (!string.IsNullOrEmpty(classTp.BindingClassMacro))
                                {
                                    gen.Line("#endif");
                                }
                            }
                        }
                    }
                }
            }

            // partial TemplateManager
            gen.Line("// ----------------------------------------------------------------------------");
            GenCode_CS_Mgr(gen, batch);
            gen.Line();

            writer.Flush();
            code = writer.ToString();
            return(true);
        }
Esempio n. 4
0
 partial void Convert(Assembly asm, BatchInfo batch);