Exemplo n.º 1
0
    /// <summary>
    /// 生成CS类
    /// </summary>
    private static void GenerateClassCode(string name, DataTable table)
    {
        if (data_list.Count <= 0)
        {
            Debug.LogError(string.Format("{0}----------->没读到数据", name));
            return;
        }

        //生成文件
        string        className = string.Format("Config{0}", ExeclUtil.FirstCharToUpper(name));
        StringBuilder classsb   = new StringBuilder();

        classsb.Append(classTemplate);

        StringBuilder property = new StringBuilder();

        property.Append("\n");
        StringBuilder read = new StringBuilder();

        read.Append("//read");
        read.Append("\n");
        StringBuilder write = new StringBuilder();

        write.Append("//write");
        write.Append("\n");

        for (int i = 0; i < data_list.Count; i++)
        {
            property.Append("\t\t");
            property.Append("/// <summary>\n");
            property.Append("\t\t");
            property.AppendFormat("///{0}\n", data_list[i].desc);
            property.Append("\t\t");
            property.Append("/// </summary>\n");
            property.Append("\t\t");
            property.AppendFormat("public {0} {1};\n", data_list[i].type, data_list[i].key);

            read.Append("\t\t\t");
            read.AppendFormat("{0} = info.{1}(\"{2}\");\n", data_list[i].key, ExeclUtil.GetMethod(data_list[i].type), data_list[i].key);

            write.Append("\t\t\t");
            write.AppendFormat("info.AddValue(\"{0}\", {1});\n", data_list[i].key, data_list[i].key);
        }
        ;

        classsb.Replace("%CLASSNAME%", className);
        classsb.Replace("%PROPERTY&", property.ToString());
        classsb.Replace("%READ%", read.ToString());
        classsb.Replace("%WRITE%", write.ToString());

        string file_path = PathUtil.GetRegularPath(string.Format("{0}{1}.cs", class_path, className));

        if (File.Exists(file_path))
        {
            File.Delete(file_path);
        }
        File.WriteAllText(file_path, classsb.ToString(), Encoding.UTF8);

        Debug.Log("生成代码文件 ----->" + file_path);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 生成打包代码
    /// </summary>
    private static void GenerateCreatorCode(string name, DataTable table)
    {
        if (data_list.Count <= 0)
        {
            Debug.LogError(string.Format("{0}----------->没读到数据", name));
            return;
        }

        //生成文件
        string        className  = string.Format("{0}Creator", ExeclUtil.FirstCharToUpper(name));
        string        configName = string.Format("Config{0}", ExeclUtil.FirstCharToUpper(name));
        StringBuilder classsb    = new StringBuilder();

        classsb.Append(creatorTemplate);

        StringBuilder read = new StringBuilder();

        read.Append("\n");

        for (int i = 0; i < data_list.Count; i++)
        {
            ExcelData data = data_list[i];
            read.Append("\t\t\t");
            read.AppendFormat("c.{0} = {1}(\"{2}\", i);\n", data.key, ExeclUtil.GetMethod(data_list[i].type), data.key);
        }

        classsb.Replace("%READ%", read.ToString());
        classsb.Replace("%CLASSNAME%", className);
        classsb.Replace("%CONFIGNAME%", configName);

        string file_path = PathUtil.GetRegularPath(string.Format("{0}{1}.cs", creator_path, className));

        if (File.Exists(file_path))
        {
            File.Delete(file_path);
        }
        File.WriteAllText(file_path, classsb.ToString(), Encoding.UTF8);

        Debug.Log("生成打包文件 ----->" + file_path);
    }