Exemplo n.º 1
0
        private static Class BuildBaseClass(Record record, Dictionary<string, Record> AllRecords)
        {
            string className = record.Name;
            Class baseClass = new Class(className);
            baseClass.Modifiers.Add("public");
            baseClass.Modifiers.Add("partial");
            if (record.Parent != null)
            {
                baseClass.BaseClass = record.Parent;
                baseClass.Constructors.Add(String.Format("public {0}() {{ }}", className));
                baseClass.Constructors.Add(String.Format(
                    "public {0}({1} record) : base(record) {{ }}",
                    className, baseClass.BaseClass
                    ));
                if (record.Fields.Count > 0)
                {
                    foreach (RecordField member in record.Fields)
                    {
                        Field field = new Field(member.Type, member.Name);
                        field.Modifiers.Add("public");
                        if (member.Description != null)
                        {
                            field.Summary = member.Description;
                        }
                        baseClass.Members.Add(field);
                    }
                }
            }
            else
            {
                Method method = new Method(className, "Read");
                method.Modifiers.Add("public");
                method.Modifiers.Add("static");
                method.Params.Add(new Parameter("Stream", "stream"));

                method.MethodBody.Add(String.Format("{0} record = {0}.ReadBase(stream);", className));
                CodeBlock switchblock = new CodeBlock("switch (record.Type)");
                AddChildCase(record, className, switchblock);
                CodeLines defaultblock = new CodeLines();
                defaultblock.Lines.Add("default:");
                defaultblock.Lines.Add("\treturn record;");
                switchblock.Add(defaultblock);
                method.MethodBody.Add(switchblock);

                baseClass.Members.Add(method);
            }
            return baseClass;
        }
Exemplo n.º 2
0
        public static Class BuildClass(Record record, Dictionary<string, Record> allRecords)
        {
            string className = record.Name;
            string baseName = record.Parent;
            while (allRecords[baseName].Parent != null)
            {
                baseName = allRecords[baseName].Parent;
            }
            Class elementClass = new Class(className);
            elementClass.Summary = record.Description;
            elementClass.Modifiers.Add("public");
            elementClass.Modifiers.Add("partial");
            elementClass.BaseClass = record.Parent;
            elementClass.Constructors.Add(
                String.Format("public {0}({1} record) : base(record) {{ }}", className, baseName));

            Constructor constructor = new Constructor(elementClass);
            constructor.MethodBody.Add(String.Format("this.Type = {0}Type.{1};", baseName, className));
            foreach (RecordField member in record.Fields)
            {
                if (member.Type.StartsWith("List<") || member.Type.StartsWith("FastSearchList<"))
                {
                    constructor.MethodBody.Add(String.Format("this.{0} = new {1}();", member.Name, member.Type));
                }
            }
            elementClass.Members.Add(constructor);

            foreach (RecordField member in record.Fields)
            {
                Field field = new Field(member.Type, member.Name);
                field.Modifiers.Add("public");
                if (member.Description != null)
                {
                    field.Summary = member.Description;
                }
                elementClass.Members.Add(field);
            }
            List<RecordField> members = GetAllMembers(record, allRecords);
            if (members.Count > 0)
            {
                elementClass.Members.Add(DecodeMethod(record, baseName, members));
                elementClass.Members.Add(EncodeMethod(record, baseName, members));
            }
            return elementClass;
        }