question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set to true nullable bool arguments without the value

See original GitHub issue

Consider 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:open
  • Created 5 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

10reactions
mansellancommented, Apr 22, 2020

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 for bool?, it will accept:

  1. --{option} => true
  2. --{option}=true|false => value
  3. (omitted) => null

2 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.

1reaction
markdulfercommented, Oct 1, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found