I am using the settings designer and have noticed that I'm limited to standard types in my settings file. I would like to use some of my custom types that I'm working with in my app. Is this possible
Thanks,
Devin
I am using the settings designer and have noticed that I'm limited to standard types in my settings file. I would like to use some of my custom types that I'm working with in my app. Is this possible
Thanks,
Devin
Boy, thought this would be an easy one to answer.
Hi, Devin
Yes, you can. However the visual designer does not seem to support this so you have to do some manual work.
First you need to create a new application setting class that derives from ApplicationSettingsBase as follows:
How to: Create Application Settings
Then add your new type like this:
[ApplicationScopedSetting()]
[SettingsSerializeAs(SettingsSerializeAs.Binary)]
[DefaultSettingValue(@"AAEAAAD/////AQAAAAAAAAAMAgAAAEpXaW5kb3dzQXBwbGljYXRpb240LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAHldpbmRvd3NBcHBsaWNhdGlvbjQuQ3VzdG9tRGF0YQIAAAAEbmFtZQR0aW1lAQANAgAAAAYDAAAAB0NTIFRhbmdZNHHJs83JiAs=")]
public CustomData Data
{
get
{
return (CustomData)this["Data"];
}
set
{
this["Data"] = (CustomData)value;
}
}
Note that how the data should be serialized is specified by the SettingsSerializeAs attribute. The default value is specified by DefaultSettingValue attribute. The value itself should be generated by yourself.
Finally you can retrieve the data with an instance of the new application settings class.
CustomSettings cs = new CustomSettings();
CustomData lastData = cs.Data;
Best Regards
Chunsheng Tang
This way I cannot use the designer can I