How to reload different objects by applicationsettingsbase?

Posted by younevertell on Stack Overflow See other posts from Stack Overflow or by younevertell
Published on 2010-04-23T15:32:46Z Indexed on 2010/04/23 15:33 UTC
Read the original article Hit count: 260

Filed under:

// TestASettingsString and TestBSettingsString are byte[] // TestASettings and TestBSettings are two objects to be saved

My question is how to recover TestASettings and TestBSettings from TestASettingsString and TestASettingsString seperately in loadsavedsettings?

Thanks

private void SettingsSaving(object sender, CancelEventArgs e) {

        try
        {
            var stream = new MemoryStream();
            var formatter = new BinaryFormatter();
            formatter.Serialize(stream, TestASettings);
    // TestASettingsString and TestBSettingsString are byte[]
            TestASettingsString = stream.ToArray();

            stream.Flush();
            formatter.Serialize(stream, TestBSettings);
            TestBSettingsString = stream.ToArray();   

            stream.Close();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
    }

private void LoadSavedSettings() { Reload(); // how to get TestASettings and TestBSettings from TestASettingsString and // TestASettingsString seperately? }

© Stack Overflow or respective owner

Related posts about c#