Static property override
I have a base class
BaseOptions
and it has name value, that I will override in each child class.
Base Class
Child Class
Usage
What should I use to create structure like above?7 Replies
is this static? because i see no
static
(also static is kind of outside inheritance -- which i wouldn't even use in this case)
((although still you should be able to use new
to override a member))This is pseudo code, I show what I want to achieve
I'm asking for a way to do it, because I don't know how
as apprendeur said, static lies outside the concept of oops, so you can't achieve dynamic configuration binding like this unless you instantate it as an object...
2 way I can suggest is...
1) Use reflection to get the class name and the classname can be the one that key
2) You can use Attributes and play along a bit with it
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
That's a good suggestion, I will change it. For example I created abstract class
OptionsBase
that has static field Name
Then I inherit ApplicationOptions
from it
How can I override override static property Name
that is in OptionsBase
class. Should I create a constructor, will it work with .AddOptions
? The have name in each Options class that I can use in .BindConfiguration
. The name is the same as section name in appsettings.json
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
now I get it, thank you