/// <summary>Saves a value to a key in this ES3File.</summary> /// <param name="key">The key we want to use to identify our value in the file.</param> /// <param name="value">The value we want to save.</param> public void Save <T>(string key, T value) { var unencryptedSettings = (ES3Settings)settings.Clone(); unencryptedSettings.encryptionType = ES3.EncryptionType.None; unencryptedSettings.compressionType = ES3.CompressionType.None; cache[key] = new ES3Data(ES3TypeMgr.GetOrCreateES3Type(typeof(T)), ES3.Serialize(value, unencryptedSettings)); }
/// <summary>Saves a value to a key in this ES3File.</summary> /// <param name="key">The key we want to use to identify our value in the file.</param> /// <param name="value">The value we want to save.</param> public void Save <T>(string key, T value) { var unencryptedSettings = (ES3Settings)settings.Clone(); unencryptedSettings.encryptionType = ES3.EncryptionType.None; unencryptedSettings.compressionType = ES3.CompressionType.None; // If T is object, use the value to get it's type. Otherwise, use T so that it works with inheritence. cache[key] = new ES3Data(ES3TypeMgr.GetOrCreateES3Type(typeof(T)), ES3.Serialize(value, unencryptedSettings)); }
public void Save(string key, object value) { using (var stream = new MemoryStream(settings.bufferSize)) { var unencryptedSettings = (ES3Settings)settings.Clone(); unencryptedSettings.encryptionType = ES3.EncryptionType.None; var es3Type = ES3TypeMgr.GetOrCreateES3Type(value.GetType()); using (var baseWriter = ES3Writer.Create(stream, unencryptedSettings, false, false)) baseWriter.Write(value, es3Type); cache[key] = new ES3Data(es3Type, stream.ToArray()); } }