More attributes in Appsettings

Asked

Viewed 106 times

2

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

Standard values:

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

I’d like to leave you like this:

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

New values will be saved by an external application.

3 answers

3

Inside the Settings app you can put only Key and Value.

Try using several different Ttings.

Example:

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

To retrieve an item within C#, use:

var nome = System.Configuration.ConfigurationManager.AppSettings["Nome"];

0

I think I’d look like this:

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

0

Name and Value Only

You can add other values to Appsettings without breaking with applying?

The answer to your question, to include new attributes, is nay. This happens because the appSettings is a serialization of NameValueCollection which is a collection of items that has a name and a value.

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

In addition to the example of MS itself, in that OS response has a simple example of implementation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.