More attributes in AppSettings

2

Is it possible to add other values to AppSettings without breaking with the application?

Default values:

<appSettings> 
    <add key="Nome" value="ValorTeste" /> 
</appSettings>

I would like to leave it like this:

<appSettings> 
    <add key="Nome" value="ValorTeste" roles="TESTE" title="TESTE" />
</appSettings>

The new values will be saved by an external application.

    
asked by anonymous 03.05.2017 / 19:30

3 answers

3

Within the app settings you can for only Key and Value.

Try using several different settings.

Example:

<appSettings> 
    <add key="Nome" value="ValorTeste" />
    <add key"Teste" value="Teste" />
</appSettings>

To retrieve an item within the C # code, use:

var nome = System.Configuration.ConfigurationManager.AppSettings["Nome"];
    
03.05.2017 / 20:13
0

I think it would look like this:

<appSettings>
 <add key="Nome" value="ValorTeste" />
 <add key="Rules" value="TESTE" />
 <add key="Title" value="Teste" />
</appSettings>
    
03.05.2017 / 19:38
0

Name and Value only

  

You can add other values to AppSettings without breaking with the   application?

The answer to your question, to include new attributes, is no . This is because appSettings is a serialization of NameValueCollection "which is a collection of items that have a name and a value.

If you need a configuration alternative you can use an implementation of a configuration section of your own application by extending the ConfigurationSection ". By doing this you build classes with your own parameters and evolve as your application grows.

In addition to the MS instance itself, in this SO response has a simple implementation example.

    
03.05.2017 / 20:32