我爲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;
}
}
}
}
哪個不起作用。顯然它不理解'屬性'語法。
任何想法我做錯了什麼?謝謝。
請問您可以發佈LoadValuesFromXml方法的代碼嗎?我認爲您的問題可能會阻礙您從XmlNode中檢索包含自定義部分信息的值。 – 2010-11-26 09:42:20
我正在擴展配置設置。將添加該代碼。 – Damien 2010-11-26 10:41:26