Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Orace
Copy link

@Orace Orace commented Dec 12, 2022

Fix for #862

@Orace Orace changed the title Issue862 Fix #862. Properties with required modifier should be required. Dec 12, 2022
private class Options
{
[Option("cols")]
public required int Cols { get; set; }

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

Copy link
Author

@Orace Orace Dec 13, 2022

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

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants