예제 #1
0
        public void TestBuild()
        {
            this.tracer.WriteLine("测试方法 Build(string, Regex, string)");

            try
            {
                File.WriteAllText(@"temp.txt", "小马:22\n小红:25");

                this.tracer.WriteLine(string.Format("成功: 转化文件 temp.txt 为 sql 脚本 {0}, 由于没有指定编码, 所以可能出现乱码, 无法正常转化", CodingHelper.Build("INSERT INTO student (name, age) VALUES ('$1', $2)", new Regex("(\\w+):(\\w+)$", RegexOptions.Multiline), @"temp.txt")));
            }
            catch (Exception err)
            { this.tracer.WriteLine(string.Format("异常: {0}", err.Message)); }


            this.tracer.WriteLine("测试方法 Build(string, Regex, string, Encoding)");

            try
            {
                File.WriteAllText(@"temp.txt", "小马:22\n小红:25", Encoding.UTF8);

                this.tracer.WriteLine(string.Format("成功: 转化 UTF8 编码文件 temp.txt 为 sql 脚本 {0}", CodingHelper.Build("INSERT INTO student (name, age) VALUES ('$1', $2)", new Regex("(\\w+):(\\w+)$", RegexOptions.Multiline), @"temp.txt", Encoding.UTF8)));
            }
            catch (Exception err)
            { this.tracer.WriteLine(string.Format("异常: {0}", err.Message)); }


            this.tracer.WriteLine("测试方法 Build(string, string, Regex)");

            try
            { this.tracer.WriteLine(string.Format("成功: 转化文本 '小马:22\\n小红:25' 为 sql 脚本 {0}", CodingHelper.Build("INSERT INTO student (name, age) VALUES ('$1', $2)", "小马:22\n小红:25", new Regex("(\\w+):(\\w+)$", RegexOptions.Multiline)))); }
            catch (Exception err)
            { this.tracer.WriteLine(string.Format("异常: {0}", err.Message)); }

            this.tracer.WaitPressEnter();
        }