Add custom type to settings.settings

I would like to use the .settings configuration file to save this structure:

struct sR22Protocole { Int32 inputkey; Int32 outputkey; Int32 voltage; Int32 Ohm; Int32 Correction; }; 

In the settings designer, I can add another type, but it does not display my structure in the view section. Is there a way that a designer has access to my structure? If not, is there a way to add it programmatically?

+8
c # settings.settings
source share
3 answers

I believe that a class (or struct?) Should be serialized for use in the settings file. I followed this blog post when I did this for the default object in the application:

http://www.blackwasp.co.uk/CustomAppSettings.aspx

+6
source share

Just go to the overview section and enter the name of the structure, class, or enumeration, after specifying it with the namespace of your type. Then it will also be added to the drop-down list for your next use.

In your example: YourTypeNamespace.sR22Protocole

+4
source share

Your type should have the SettingsSerializeAs() attribute. The enum parameter of type SettingsSerializeAs indicates how the value will be serialized, the following values ​​are possible:

  • Line
  • Xml
  • Binary
  • ProviderSpecific

Since this attribute can only be applied to class types, your own type must be a class.

Secondly, the type must have a constructor without parameters. This is because if a parameter is not specified in the App.config file, the default value for this parameter will be set in the setting.

If you have just declared your class, the designer will not accept the type if you have not created your solution.

+4
source share

All Articles