T
Tony Tallman
Is there a way to store an object of a user defined type in the applications
settings?
I have compiled the type in a dll and referenced the dll into my
application.
I have applied the [Serializable] attribute to my user defined type.
I can create a settings property of the correct type, but it won't serialize
(or won't deserialize).
Example:
public class State
{
bool b1;
string s1;
int n1;
public State(bool b, string s, int n)
{
b1=b; s1=s; n1=1;
}
}
public void TestStateSetting()
{
Settings.Default.MyState = new State(true, "Hi", 0);
Settings.Default.MyString = "System.string serializes ok";
// Save and reload settings to simulate program shutdown and restart.
Settings.Default.Save();
Settings.Default.Reload();
// Primitive types work but user defined (and other system types) don't
work.
MessageBox.Show("Settings.Default.MyState == null !!");
MessageBox.Show("Settings.Default.MyString == 'System.string serializes
ok'");
}
settings?
I have compiled the type in a dll and referenced the dll into my
application.
I have applied the [Serializable] attribute to my user defined type.
I can create a settings property of the correct type, but it won't serialize
(or won't deserialize).
Example:
public class State
{
bool b1;
string s1;
int n1;
public State(bool b, string s, int n)
{
b1=b; s1=s; n1=1;
}
}
public void TestStateSetting()
{
Settings.Default.MyState = new State(true, "Hi", 0);
Settings.Default.MyString = "System.string serializes ok";
// Save and reload settings to simulate program shutdown and restart.
Settings.Default.Save();
Settings.Default.Reload();
// Primitive types work but user defined (and other system types) don't
work.
MessageBox.Show("Settings.Default.MyState == null !!");
MessageBox.Show("Settings.Default.MyString == 'System.string serializes
ok'");
}