Can't define static abstract string property

后端 未结 5 1100
别跟我提以往
别跟我提以往 2021-02-19 10:03

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

I have an abstract class that contains a static method that accep

5条回答
  •  你的背包
    2021-02-19 10:53

    What you're trying to do is impossible, as others have mentioned.

    I'd try something like this

    public abstract class ProviderConfiguration : ConfigurationSection
    {
        public string ConfigurationSectionName { get; set; }
    
        public static ProviderConfiguration Provider { get; set; }
    
        public static Configuration Current
        {
            get { return (Configuration)ConfigurationManager.GetSection(Provider.ConfigurationSectionName); }
        }
    }
    

    Then in practice:

    public void DoStuff()
    {
        var provider = new DerivedProviderConfiguration();
        ProviderConfiguration.Provider = provider;
    }
    

提交回复
热议问题