不能定义静态抽象的字符串属性 [英] Can't define static abstract string property
问题描述
我碰到一个有趣的问题,并正在寻找一些建议,就如何最好地处理这...
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.
这篇关于不能定义静态抽象的字符串属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!