-
-
Save aysegulsarikaya/6da72965a2eb228b79ffbe32f8d8ebeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var p = AddPerson(); | |
| PersonList pList = new PersonList(); | |
| pList.AddPerson("Ayşe", "KAYA", 27); | |
| pList.AddPerson("Metin", "TAŞKIN", 35); | |
| pList.AddPerson("Ali", "ŞENLİK", 25); | |
| Serialize(p, "Person.xml"); | |
| Serialize(pList, "PersonList.xml"); | |
| } | |
| static Person AddPerson() | |
| { | |
| Person p = new Person(); | |
| p.Name = "Hasan"; | |
| p.SurName = "KARACA"; | |
| p.Age = 45; | |
| return p; | |
| } | |
| static public void Serialize<T>(T obj, string aXMLName) | |
| { | |
| var xml = new XmlSerializer(typeof(T)); | |
| var xmlWriterSettings = new XmlWriterSettings | |
| { | |
| Indent = false, | |
| OmitXmlDeclaration = false, | |
| Encoding = Encoding.UTF8 | |
| }; | |
| using (var xmlWriter = XmlWriter.Create(aXMLName, xmlWriterSettings)) | |
| { | |
| xml.Serialize(xmlWriter, obj); | |
| } | |
| // using (StreamWriter sw = new StreamWriter(aXMLName, true, Encoding.UTF8)) | |
| // { | |
| // xml.Serialize(sw, obj); | |
| // } | |
| } | |
| } | |
| public class Person | |
| { | |
| public string Name; | |
| public string SurName; | |
| public int Age; | |
| } | |
| public class PersonList | |
| { | |
| public PersonList() | |
| { | |
| Persons = new List<Person>(); | |
| } | |
| public List<Person> Persons { get; set; } | |
| public void AddPerson(string aName, string aSurName, int aAge) | |
| { | |
| var p = new Person | |
| { | |
| Name = aName, | |
| SurName = aSurName, | |
| Age = aAge | |
| }; | |
| Persons.Add(p); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment