假設我在ASP.NET web.config中定義配置部分,如:是否可以在自定義配置節中擁有任意的XML?
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web">
<section name="MySettings" type="MyCompany.MyProject.Configuration.MySettings" allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="false" />
</sectionGroup>
</configSections>
<system.web>
<MySettings knownProperty="some_value" unknownProperty="other_value" />
</system.web>
</configuration>
並假設我定義MySettings : System.Configuration.ConfigurationSection
沒有unknownProperty
:
using System.Configuration;
namespace MyCompany.MyProject.Configuration
{
public class MySettings : ConfigurationSection
{
public MySettings() { }
[ConfigurationProperty("knownProperty", DefaultValue="default_value")]
public string KnownProperty
{
get { return (string)this["knownProperty"]; }
}
// I'm not defining unknownProperty here on purpose
}
}
反正是有運行應用程序,而不抱怨無法識別的屬性「unknownProperty」的配置錯誤?
此外,我會很好的方式來捕捉錯誤,如果可能的話忽略它。
換句話說,我希望XML具有未綁定到的匹配類型中定義的屬性。它可以在現有配置API的範圍內完成嗎?