Set to true nullable bool arguments without the value
See original GitHub issueConsider the following class:
class Parameters
{
[Option("bool")]
public bool Bool { get; set; }
[Option("nullable-bool")]
public bool? NullableBool { get; set; }
}
It works fine for such arguments: --bool --nullable-bool true
but doesn’t work for --bool --nullable-bool
.
I suggest making it working for nullable bool types.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:12
Top Results From Across the Web
Nullable bool or bool with default value in action?
I think default value in Route configuration will be best. It depends of the role of your bool. If you want to have...
Read more >Nullable value types - C# reference
Learn about C# nullable value types and how to use them. ... any of the following three values to a bool? variable: true...
Read more >Should I use Nullable bool? - Adam Storr
A boolean in .NET is a struct hence is a value type and can not be null. By definition a bool value is...
Read more >bool type - C# reference
The bool type keyword is an alias for the .NET System.Boolean structure type that represents a Boolean value, which can be either true...
Read more >c# - Nullable boolean value with property
Nullable <T> has a method called GetValueOrDefault which is the equivalent of your code as false is default(bool) . – RobH · This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Similar use-case. I want to allow
--verbose
or--quiet
, but in my case, command line args are just one possible source for this (another is saved configuration). So I’d like it to be able to infer that forbool?
, it will accept:--{option}
=> true--{option}=true|false
=> value(omitted)
=> null2 and 3 work just fine, but command-line users are used to using 1 for quickly switching things on, and I’d like to accomodate that.
I have a scenario where default settings are pulled from a database, but I want the ability to override certain settings with a commandline switch. In this case, I actually do want a nullable bool for flags. If the switch is not passed on the commandline (hence value = null) then use the default that came from the database, otherwise override with the commandline switch.