Windows フォーム アプリケーションの app.config ファイルにカスタム セクションを追加しました。構成ファイルを拡張するクラスを作成しました。
CustomFields myCustomFields = (CustomFields)System.Configuration.ConfigurationManager.GetSection("CustomFields");
セクション名を指定します。
<section name="CustomFields" type="Application.Core.CustomFields, ATMCardRequest.Core" allowLocation="true" allowDefinition="Everywhere" />
さて、ここが問題だと思います。上記は以前はうまく機能していましたが、このセクションには多くのプロパティが必要であり、これを行う代わりに:
<CustomFields setting1='hello' setting2='world'/>
私はこれをやっています:
<CustomFields>
<property name="setting1">hello</property>
<property name="setting2">world</property>
...
</CustomFields>
コード:
/// <summary>
/// Settings file which holds the name of the XML Fields
/// </summary>
public class setting1: ConfigurationSection
{
/// <summary>
/// Name of the setting1 Field
/// </summary>
[ConfigurationProperty("setting1", IsRequired = true)]
public String setting1
{
get
{
return (String)this["setting1"];
}
set
{
this["setting1"] = value;
}
}
/// <summary>
/// Name of the setting2 Field
/// </summary>
[ConfigurationProperty("setting2",IsRequired = true)]
public String setting2
{
get
{
return (String)this["setting2"];
}
set
{
this["setting2"] = value;
}
}
}
}
これは機能していません。どうやら「プロパティ」構文を理解していないようです。
私が間違っていることはありますか?ありがとう。