Example #1
0
 private string GenListReadCode(Type type, Type valueType, BaseGenerator gen)
 {
     return(string.Format(
                "		int size = o.ReadInt32();\n"+
                "		d = new {0}(size);\n"+
                "		for(int i = 0; i < size; ++i)\n"+
                "		{{\n"+
                "			{1} elem;\n"+
                "			{2};\n"+
                "			d.Add(elem);\n"+
                "		}}\n"+
                "",
                TypeName(type),
                gen.TypeName(valueType),
                gen.ReadExpression(valueType, "elem")
                ));
 }
 protected virtual string GenListReadCode(Type type, Type keyType, Type valueType, BaseGenerator keyGen, BaseGenerator valueGen)
 {
     return(string.Format(
                "		int size = o.ReadInt32();\n"+
                "		d = new {0}(size);\n"+
                "		for(int i = 0; i < size; ++i)\n"+
                "		{{\n"+
                "			{1} key;\n"+
                "			{2};\n"+
                "			{3} value;\n"+
                "			{4};\n"+
                "			d.Add(key, value);\n"+
                "		}}\n",
                TypeName(type),
                keyGen.TypeName(keyType),
                keyGen.ReadExpression(keyType, "key"),
                valueGen.TypeName(valueType),
                valueGen.ReadExpression(valueType, "value")
                ));
 }
    private string GenArrayReadCode(Type valueType, BaseGenerator gen)
    {
        string valueTypeName = gen.TypeName(valueType);
        string str           = "";

        if (valueTypeName.Contains("[]"))
        {
            valueTypeName = valueTypeName.Substring(0, valueTypeName.IndexOf('['));
            str           = "[]";
        }
        return(string.Format(
                   "		int size = o.ReadInt32();\n"+
                   "		d = new {0}[size]{2};\n"+
                   "		for(int i = 0; i < size; ++i)\n"+
                   "		{{\n"+
                   "			{1};\n"+
                   "		}}\n"+
                   "",
                   valueTypeName,
                   gen.ReadExpression(valueType, "d[i]"),
                   str
                   ));
    }