public void WriteListOfObjectTest() { GroupOfPerson origin = new GroupOfPerson(); origin.Persons.Add(new Person() { FirstName = "Alice", LastName = "Cooper", DateOfBirth = DateTime.Parse("4/02/1948") }); origin.Persons.Add(new Person() { FirstName = "Marilyin", LastName = "Manson", DateOfBirth = DateTime.Parse("5/01/1969") }); CSharpIniFileSerializer.IniSerializer.IniWriter writer = new CSharpIniFileSerializer.IniSerializer.IniWriter(); writer.settings = new IniSettings() { SetTypeInfo = TypeInfo.Properties, DefaultArrayType = ArrayType.Section }; writer.Serialize<GroupOfPerson>(origin, Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest.ini")); GroupOfPerson serialized = new GroupOfPerson(); using (StreamReader sr = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest.ini"), true)) { CSharpIniFileSerializer.IniSerializer.IniReader reader = new CSharpIniFileSerializer.IniSerializer.IniReader(); reader.settings = new IniSettings() { SetTypeInfo = TypeInfo.Properties, DefaultArrayType = ArrayType.Section }; reader.Deserialize<GroupOfPerson>(ref serialized, sr); } writer = new CSharpIniFileSerializer.IniSerializer.IniWriter(); writer.settings = new IniSettings() { SetTypeInfo = TypeInfo.Properties, DefaultArrayType = ArrayType.Section }; writer.Serialize<GroupOfPerson>(serialized, Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest_serialized.ini")); Assert.AreEqual(origin.Persons.Count, serialized.Persons.Count); for (int i = 0; i < origin.Persons.Count; i++) { Assert.AreEqual(origin.Persons[i].FirstName, serialized.Persons[i].FirstName); Assert.AreEqual(origin.Persons[i].LastName, serialized.Persons[i].LastName); Assert.AreEqual(origin.Persons[i].DateOfBirth, serialized.Persons[i].DateOfBirth); } }
public void WriteObjectOfListOfObjectTest() { IniSettings settings = new IniSettings() { SetTypeInfo = TypeInfo.Properties, DefaultArrayType = ArrayType.Section }; GroupOfGroupOfPerson origin = new GroupOfGroupOfPerson(); GroupOfPerson groupOfPerson = new GroupOfPerson(); groupOfPerson.Persons.Add(new Person() { FirstName = "Alice", LastName = "Cooper", DateOfBirth = DateTime.Parse("4/02/1948") }); groupOfPerson.Persons.Add(new Person() { FirstName = "Marilyin", LastName = "Manson", DateOfBirth = DateTime.Parse("5/01/1969") }); GroupOfPerson groupOfPerson2 = new GroupOfPerson(); groupOfPerson2.Persons.Add(new Person() { FirstName = "Alice", LastName = "Cooper", DateOfBirth = DateTime.Parse("4/02/1948") }); groupOfPerson2.Persons.Add(new Person() { FirstName = "Marilyin", LastName = "Manson", DateOfBirth = DateTime.Parse("5/01/1969") }); origin.GroupOfPersons.Add(groupOfPerson); origin.GroupOfPersons.Add(groupOfPerson2); CSharpIniFileSerializer.IniSerializer.IniWriter writer = new CSharpIniFileSerializer.IniSerializer.IniWriter(); writer.settings = settings; writer.Serialize<GroupOfGroupOfPerson>(origin, Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest2.ini")); GroupOfGroupOfPerson serialized = new GroupOfGroupOfPerson(); using (StreamReader sr = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest2.ini"), true)) { CSharpIniFileSerializer.IniSerializer.IniReader reader = new CSharpIniFileSerializer.IniSerializer.IniReader(); reader.settings = settings; reader.Deserialize<GroupOfGroupOfPerson>(ref serialized, sr); } writer = new CSharpIniFileSerializer.IniSerializer.IniWriter(); writer.settings = settings; writer.Serialize<GroupOfGroupOfPerson>(serialized, Path.Combine(Directory.GetCurrentDirectory(), "WriteListOfObjectTest2_serialized.ini")); }