/// <summary> /// Write the Definition to file /// </summary> /// <param name="filename"></param> /// <param name="format"></param> public void WriteDefinition(string filename, DefinitionFormat format) { FixedLengthFileReader.WriteSchema(Definition, filename, format); }
public void TestRead() { var model1 = new FileModel { utf8StrField = "这是一个", intField = int.MaxValue, longField = long.MinValue, asciiStrField = "abcdefgh", intUnionField = Utf8StrToInt("这是一个"), strUnionField = "bcd", charField = char.MaxValue, byteArrField = new byte[] { 1, 2 }, dateTimeField = DateTime.Now, }; var model2 = new FileModel { utf8StrField = "测试文本", intField = 1, longField = long.MaxValue, asciiStrField = "abc", intUnionField = Utf8StrToInt("测试文本"), strUnionField = "bc", charField = char.MinValue, byteArrField = new byte[] { 1, 2 }, dateTimeField = DateTime.Now, }; var model3 = new FileModel { utf8StrField = "啦", intField = 1, longField = int.MinValue, asciiStrField = "", intUnionField = Utf8StrToInt("啦"), strUnionField = "", charField = '哈', byteArrField = new byte[] { 1, 2 }, dateTimeField = DateTime.MinValue, }; var model4 = new FileModel { utf8StrField = "abcdefg", // intField = 0, // longField = 0, asciiStrField = "123", intUnionField = Utf8StrToInt("abcdefg"), strUnionField = "23", charField = '哈', byteArrField = new byte[] { 1, 2 }, dateTimeField = DateTime.MaxValue, }; var models = new FileModel[] { model1, model2, model3, model4 }; var fileName = Path.GetTempFileName(); using (var stream = File.OpenWrite(fileName)) { var writer = new FixedLengthFileWriter <FileModel>(stream); foreach (var model in models) { writer.Write(model); } } using (var stream = File.OpenRead(fileName)) { var reader = new FixedLengthFileReader <FileModel>(stream); foreach (var model in models) { var outModel = reader.Read(); Assert.AreEqual(model, outModel); } } }
/// <summary> /// Read the Definition from file /// </summary> /// <param name="filename"></param> /// <param name="format"></param> public void ReadDefinition(string filename, DefinitionFormat format) { Definition = FixedLengthFileReader.ReadSchema(filename, format); }