问题描述
我在确切了解自定义ConfigurationSections的工作方式时遇到了真正的麻烦.以下代码摘自CodeProject(削减了一点):
Hi,
I am having real trouble understanding exactly how custom ConfigurationSections work. The following code is taken from CodeProject (cut down a bit):
public class MyConfig : ConfigurationSection
{
static SNLogConfig()
{
_configBoolValue = new ConfigurationProperty( "boolValue", typeof( bool ), false, ConfigurationPropertyOptions.None );
_configProperties.Add( _configBoolValue );
}
[ConfigurationProperty( "boolValue", IsRequired = false )]
public bool BoolValue
{
get { return (bool)base[ _configBoolValue ]; }
}
private static ConfigurationProperty _configBoolValue;
private static ConfigurationPropertyCollection _configProperties = new ConfigurationPropertyCollection();
}
我不明白的是,代码如上所示显示在Code Project上(在属性中进行数组访问之前使用 base 关键字,但是如果代码看起来一样,则代码可以正常工作我将 base 替换为 this (如MSDN示例所示).
我的派生类或基类中存储的属性集合在哪里?如果在基类中,为什么我需要在派生类中创建自己的ConfigurationPropertyCollection?
我知道我在这里有点厚,但是我对C#有点生锈,而且我一生都无法确切地了解发生了什么.任何帮助将不胜感激.
帕特里克
What I don''t understand is that the code is shown on Code Project as it is above (with the base keyword before the array access in the property, but the code appears to work just the same if I replace base with this (as shown in the MSDN example).
Where is the collection of properties being stored, in my derived class or the base class? If in the base class, why do I need to create my own ConfigurationPropertyCollection in my derived class?
I know I''m being a bit thick here, but I am a bit rusty with C#, and I just can''t for the life of me see exactly what is going on. Any help would be very much appreciated.
Kind wishes, Patrick
推荐答案
这篇关于努力了解自定义配置部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!