Skip to content

Fix #862. Properties with required modifier should be required. - #863

Open
Orace wants to merge 3 commits into
commandlineparser:masterfrom
Orace:Issue862
Open

Orace wants to merge 3 commits into
commandlineparser:masterfrom
Orace:Issue862

Conversation

@Orace

@Orace Orace commented Dec 12, 2022 •

Copy link
Copy Markdown

Fix for #862

@Orace Orace changed the title Issue862 Dec 12, 2022
private class Options
{
[Option("cols")]
public required int Cols { get; set; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you have a required modifier and [Option(Required = false)]? I would say, it should throw because of conflicting settings. Please add test for such case

@Orace Orace Dec 13, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a trivia 🤔
So I moved the discussion on #862 thread, here

Comment on lines +118 to +122
#if NET7_0_OR_GREATER
var isRequired = attrs.OfType<RequiredMemberAttribute>().Any();
#else
var isRequired = false;
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if NET7_0_OR_GREATER
var isRequired = attrs.OfType<RequiredMemberAttribute>().Any();
#else
var isRequired = false;
#endif
var isRequired = false;
#if NET7_0_OR_GREATER
isRequired = attrs.OfType<RequiredMemberAttribute>().Any();
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants