public void Add(T objToXml) { // Generate ID and add to object int id = XmlMaker.GenareteId(this.directory); typeof(T).GetProperty("Id").SetValue(objToXml, id); // decode password if (this.objectHasPasswordProperty) { XmlMaker.DecodePasswordAndSetToObject(ref objToXml); } // Create directory if not exist Directory.CreateDirectory($"{this.type.Name}"); // add object to xml using (FileStream fs = new FileStream($"{this.type.Name}/{this.type.Name}{id}.xml", FileMode.Create)) { this.serializer.Serialize(fs, objToXml); } }
public void Update(T objectToUpdate) { Thread.Sleep(200); using (FileStream fs = new FileStream($"{this.type.Name}/{this.type.Name}{typeof(T).GetProperty("Id").GetValue(objectToUpdate)}.xml", FileMode.Create)) { if (this.objectHasPasswordProperty) { // decode password XmlMaker.DecodePasswordAndSetToObject(ref objectToUpdate); } // serialize this.serializer.Serialize(fs, objectToUpdate); if (this.objectHasPasswordProperty) { // encode password XmlMaker.EncodePasswordAndSetToObject(ref objectToUpdate); } } }