假设我在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的范围内完成吗?