예제 #1
0
        public void VisitReadDictionary(string variable, string reader, DictionaryTypeNode node, TextBuilder builder)
        {
            string equalityComparer = GetEqualityComparer(node.SerializeKey.Type);

            builder.WriteLine("int size = {0}.ReadInt32();", reader);
            builder.WriteLine("if({0} == null) ", variable);
            builder.WriteLine("\t{0} = new {1}(size{2});", variable, node.TypeName,
                              string.IsNullOrEmpty(equalityComparer) ? "" : ", " + equalityComparer);
            builder.WriteLine("else");
            builder.WriteLine("\t{0}.Clear();", variable);
            builder.WriteLine("for(int i = 0; i < size; ++i)");
            builder.LeftPar();
            builder.Indent();

            builder.WriteIndents();
            builder.Write("{0} key = ", node.ParameterNodes[0].TypeName);
            VisitDeserialization(string.Format("default({0})", node.ParameterNodes[0].TypeName), reader, node.SerializeKey, builder);
            builder.Write(";");
            builder.NextLine();

            builder.WriteIndents();
            builder.Write("{0} value = ", node.ParameterNodes[1].TypeName);
            VisitDeserialization(string.Format("default({0})", node.ParameterNodes[1].TypeName), reader, node.SerializeValue, builder);
            builder.Write(";");
            builder.NextLine();

            builder.WriteLine("{0}.Add(key, value);", variable);

            builder.UnIndent();
            builder.RightPar();
        }
예제 #2
0
        public void VisitWriteDictionary(string variable, string writer, DictionaryTypeNode node, TextBuilder builder)
        {
            builder.WriteLine("int size = {0}.Count;", variable);
            builder.WriteLine("{0}.Write(size);", writer);
            builder.WriteLine("foreach(var elem in {0})", variable);
            builder.LeftPar();
            builder.Indent();

            builder.WriteIndents();
            VisitSerialization("elem.Key", writer, node.SerializeKey, builder);
            builder.Write(";");
            builder.NextLine();

            builder.WriteIndents();
            VisitSerialization("elem.Value", writer, node.SerializeValue, builder);
            builder.Write(";");
            builder.NextLine();

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