You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm implementing a CLI app that shares some configuration settings among multiple different commands. One example is the output specification (file name or STDOUT). I'd like to create a separate ComandSettings class for just the output setting so that I can write some code like:
I also have some other command line settings that occur multiple times like DatabaseSettings, LoggingSettings, ....
The different commands whould need to compose these settings as they need. Like
publicclassListDatabaseSettings:LoggingSettings,OutputSettings{}publicclassReadDatabaseSettings:LoggingSettings,OutputSettings,DatabaseConnectionSettings,DatabaseKeySettings{}publicclassWriteDatabaseSettings:LoggingSettings,DatabaseConnectionSettings,DatabaseKeySettings{[Description("The value to write to the database.")][CommandOption("-v|--value")]publicstringValue{get;init;}}
This does not work because C# is only able to derive from one base class.
Possible Solution
If the settings could be a C# Interfaces like in commandline then it would be possible to inherit from multiple Interfaces and compose the command line parameters more freely. A possible drawback is that the final classes have to implement the interfaces.
publicinterfaceIOutputSettings{[Description("The output to store the result.")][CommandOption("-o|--output")]publicstring?Output{get;init;}}publicclassListDatabaseSettings:ComandSettings,ILoggingSettings,IOutputSettings{publicstring?LogLevel{get;init;}publicstring?Output{get;init;}}publicclassReadDatabaseSettings:ComandSettings,ILoggingSettings,IOutputSettings,IDatabaseConnectionSettings,IDatabaseKeySettings{publicstring?LogLevel{get;init;}publicstring?Output{get;init;}publicstringDatabaseUrl{get;init;}publicstringKey{get;init;}}publicclassWriteDatabaseSettings:ComandSettings,ILoggingSettings,IDatabaseConnectionSettings,IDatabaseKeySettings{publicstring?LogLevel{get;init;}publicstringDatabaseUrl{get;init;}publicstringKey{get;init;}[Description("The value to write to the database.")][CommandOption("-v|--value")]publicstringValue{get;init;}}
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered:
Context
I'm implementing a CLI app that shares some configuration settings among multiple different commands. One example is the output specification (file name or STDOUT). I'd like to create a separate ComandSettings class for just the output setting so that I can write some code like:
I also have some other command line settings that occur multiple times like DatabaseSettings, LoggingSettings, ....
The different commands whould need to compose these settings as they need. Like
This does not work because C# is only able to derive from one base class.
Possible Solution
If the settings could be a C# Interfaces like in commandline then it would be possible to inherit from multiple Interfaces and compose the command line parameters more freely. A possible drawback is that the final classes have to implement the interfaces.
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: