努力了解自定义配置部分 [英] Struggling to understand Custom ConfigurationSections

查看:54
本文介绍了努力了解自定义配置部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在确切了解自定义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

推荐答案

亲切的祝愿当您说以下代码摘自CodeProject"时,我假设您是在这里指的是一些文章.在这种情况下,最好在文章末尾的论坛中发布您的问题,以便作者可以为您提供帮助.
When you say "The following code is taken from CodeProject", I assume you are referring to some Article here. In which case it is best to post your question in the forum at the end of the article so the author can help you.


对不起-好主意.

-帕特里克
Sorry - good idea.

- Patrick


这篇关于努力了解自定义配置部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆