Generisches, komprimiertes, serialisieren von Objekten
public static void Save<T>(T obj, string path) {
DirectoryInfo di = new FileInfo(path).Directory;
if(obj != null && di != null && di.Exists) {
using(FileStream fs = new FileStream(path, FileMode.Create)) {
using(GZipStream zip = new GZipStream(fs, CompressionMode.Compress)) {
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(zip, obj);
}
}
}
}
Kommentare zum Snippet