Пользовательский app.config Конфигуратор Раздел Обработчик

Самый простой способ:

Сохранить:

getPreferences(MODE_PRIVATE).edit().putString("Name of variable",value).commit();

Для извлечения:

your_variable = getPreferences(MODE_PRIVATE).getString("Name of variable",default value);
30
задан Tshepang 7 March 2014 в 19:37
поделиться

3 ответа

First you add a property in the class that extends Section:

[ConfigurationProperty("pages", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(PageCollection), AddItemName = "add")]
public PageCollection Pages {
    get {
        return (PageCollection) this["pages"];
    }
}

Then you need to make a PageCollection class. All the examples I've seen are pretty much identical so just copy this one and rename "NamedService" to "Page".

Finally add a class that extends ObjectConfigurationElement:

public class PageElement : ObjectConfigurationElement {
    [ConfigurationProperty("title", IsRequired = true)]
    public string Title {
        get {
            return (string) this["title"];
        }
        set {
            this["title"] = value;
        }
    }

    [ConfigurationProperty("url", IsRequired = true)]
    public string Url {
        get {
            return (string) this["url"];
        }
        set {
            this["url"] = value;
        }
    }
}

Here are some files from a sample implementation:

28
ответ дан 27 November 2019 в 22:35
поделиться

You should also check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.

Highly recommended, well written and extremely helpful!

9
ответ дан 27 November 2019 в 22:35
поделиться

Кроме того, если вы часто создаете разделы конфигурации, есть Конструктор разделов конфигурации , графический дизайнер предметно-ориентированного языка для проектирования разделов конфигурации.

4
ответ дан 27 November 2019 в 22:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: