不能定义静态抽象的字符串属性字符串、抽象、静态、属性

由网友(久居孤岛无人问)分享简介:我碰到一个有趣的问题,并正在寻找一些建议,就如何最好地处理这... I've run into an interesting problem and am looking for some suggestions on how best to handle this...我有一个包含一个接受,我想定义为一个抽象的财...

我碰到一个有趣的问题,并正在寻找一些建议,就如何最好地处理这...

I've run into an interesting problem and am looking for some suggestions on how best to handle this...

我有一个包含一个接受,我想定义为一个抽象的财产静态字符串的静态方法的抽象类。问题是,C#不不支持以下内容(请参阅 ConfigurationSectionName 和当前属性):

I have an abstract class that contains a static method that accepts a static string that I would like to define as an abstract property. Problem is that C# doesn't doesn't support the following (see the ConfigurationSectionName and Current properties):

    public abstract class ProviderConfiguration : ConfigurationSection
    {
        private const string _defaultProviderPropertyName = "defaultProvider";
        private const string _providersPropertyName = "providers";

        protected static string ConfigurationSectionName { get; }

        public static Configuration Current
        {
            get { return Configuration)ConfigurationManager.GetSection(ConfigurationSectionName); }
        }
    }

我想一个办法来处理这​​将是使 ConfigurationSectionName 不是抽象的,然后创建 ConfigurationSectionName 在派生类,而是那种感觉$ P $的新定义ptty的的hackish。任何建议将是最受欢迎的。

I suppose one way to handle this would be to make ConfigurationSectionName NOT abstract and then create a new definition of ConfigurationSectionName in the derived classes, but that feels pretty hackish. Any suggestions would be most welcome.

Gratias!

推荐答案

静态成员没有多态性,所以它们不能是抽象的。 :(

Static members do not have polymorphism, so they can't be abstract. :(

如果这就是你所需要的,考虑制定辛格尔顿的对象,并读取属性关闭该对象。

If that's what you need, consider making a Singleton object, and reading the property off that object.

阅读全文

相关推荐

最新文章