コード例 #1
0
        public void VisitWriteList(string variable, string writer, ListTypeNode node, TextBuilder builder)
        {
            builder.WriteLine("int size = {0}.Count;", variable);
            builder.WriteLine("{0}.Write(size);", writer);
            builder.WriteLine("for(int i = 0; i < size; ++i)");
            builder.LeftPar();
            builder.Indent();

            builder.WriteIndents();
            VisitSerialization(variable + "[i]", writer, node.Serialize, builder);
            builder.Write(";");
            builder.NextLine();

            builder.UnIndent();
            builder.RightPar();
        }
コード例 #2
0
        public void VisitReadList(string variable, string reader, ListTypeNode node, TextBuilder builder)
        {
            builder.WriteLine("int size = {0}.ReadInt32();", reader);
            builder.WriteLine("if({0} == null) ", variable);
            builder.WriteLine("\t{0} = new {1}(size);", variable, node.TypeName);
            builder.WriteLine("else if({0}.Count != size)", variable);
            builder.WriteLine("\t{0}.Clear();", variable);
            builder.WriteLine("for(int i = 0; i < size; ++i)");
            builder.LeftPar();
            builder.Indent();

            builder.WriteIndents();
            builder.Write("var temp = ", variable);
            VisitDeserialization(string.Format("(d.Count > i ? d[i] : default({0}))", node.ParameterNodes[0].TypeName), reader, node.Serialize, builder);
            builder.Write(";");
            builder.NextLine();

            builder.WriteLine("if(d.Count <= i) d.Add(temp); else d[i] = temp;");

            builder.UnIndent();
            builder.RightPar();
        }