public void SaveDatabase <T>(string path, T tracker) { IWrapperProvider wrapperProvider = trackerfactory.GetWrapperProvider(); //check if path exist if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } //make backup if (File.Exists(path)) { BackupDatabase(wrapperProvider, path); } //standard serialization using (TextWriter writer = new StreamWriter(path)) { var xml = new XmlSerializer(typeof(T)); xml.Serialize(writer, tracker); } }