Esempio n. 1
0
        public static void LoadCsv(this ILanguageModule module, string path, bool rewrite = true)
        {
            var dw    = DataTableTool.CreateReader(new StreamReader(path, Encoding.UTF8), new DataRow(), new DataExplainer());
            var pairs = dw.Get <LanPair>();

            module.Load(pairs, rewrite);
        }
Esempio n. 2
0
        //ICsvRow 需要根据具体情况改写一下分离字符串
        //ICsvExplainer 基本不用改
        //读取时候 具体的类型需要有一个公共的无参数构造函数,否则ICsvExplainer 需要改动
        void Read()
        {
            var r =
                DataTableTool.CreateReader(new System.IO.StreamReader(path, System.Text.Encoding.UTF8),
                                           new DataRow(),
                                           new DataExplainer());
            var cc = r.Get <Man>();

            foreach (var c in cc)
            {
                Log.L(string.Format("Age {0}   Sex  {1}  Name   {2}", c.age, c.sex, c.Name));
            }
            r.Dispose();
        }
Esempio n. 3
0
        /// <summary>
        /// 对象的反序列化操作
        /// </summary>
        void Read()
        {
            Log.L("");
            Log.L("开始从本地反序列化出对象,注意分离符要与写入时一致:");
            var r =
                DataTableTool.CreateReader(new System.IO.StreamReader(path, System.Text.Encoding.UTF8),
                                           new DataRow(),
                                           new DataExplainer());
            var cc = r.Get <HuMan>();

            Log.L("读取出的列表对象的内容为:\n");
            Log.L("Age\tSex\tName\theight\twidth");
            foreach (var c in cc)
            {
                Log.L($"{c.age}\t{c.sex}\t{c.Name}\t{c.heigth}\t{c.width}");
            }
            r.Dispose();

            Log.L("");
            Log.L("由于height标记了DataReadColumnIndex(0)这个Attribute所以读的是age列的数据");
            Log.L("width标记了DataIgnore所以没有被写入文件(即使文件里有也不会读),所以都是0");
        }