c# - Accessing Configuration Settings in a static context -


it possible access configuration settings value in static context?

for instance, here code, fails red line stating 1 "cannot access non-static property 'settings' in static context." need value of setting.

namespace mycompany.sample.emailconnector.provider.implementation {     class gmailemailconnectorprovider : emailconnectorprovider     {         private string clientsecret = settings.clientsecret; // here error                                          ^^          public override email sendtestemail(string address, string message)         {             throw new notimplementedexception();         }     } } 

you can't access properties of object in field initializers that. need move initialization constructor

class gmailemailconnectorprovider : emailconnectorprovider {     private string clientsecret;      public gmailemailconnectorprovider()     {         clientsecret = settings.clientsecret;     } } 

also, it's not idea (access property constructor) if settings virtual, unless seal gmailemailconnectorprovider or otherwise nothing ever inherit it.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -