Example #1
0
    /// <summary>Loads the value from this ES3File with the given key into an existing object.</summary>
    /// <param name="key">The key which identifies the value we want to load.</param>
    /// <param name="obj">The object we want to load the value into.</param>
    public void LoadInto <T>(string key, T obj) where T : class
    {
        ES3Data es3Data;

        if (!cache.TryGetValue(key, out es3Data))
        {
            throw new KeyNotFoundException("Key \"" + key + "\" was not found in this ES3File. Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");
        }

        var unencryptedSettings = (ES3Settings)this.settings.Clone();

        unencryptedSettings.encryptionType  = ES3.EncryptionType.None;
        unencryptedSettings.compressionType = ES3.CompressionType.None;

        if (typeof(T) == typeof(object))
        {
            ES3.DeserializeInto(es3Data.type, es3Data.bytes, obj, unencryptedSettings);
        }
        else
        {
            ES3.DeserializeInto(es3Data.bytes, obj, unencryptedSettings);
        }
    }