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

Adding annotations based on MS guidance #4387

Closed
wants to merge 1 commit into from

Conversation

jbogard
Copy link
Member

@jbogard jbogard commented Feb 7, 2024

Reviewed the changes and added tests basically to confirm the behavior based on this guidance:

https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/api-guidelines/nullability.md

This should cover the 99.99% scenarios. People can break it intentionally but this at least shows the default behaviors?

@lbargaoanu
Copy link
Member

I'm sure there are people out there that have maps that return null for non-null source. You'll just lie to them? :) Does MS do that anywhere? I've checked System.Text.Json and it does have nullable both on the source and the result.

public TDestination Map<TDestination>(object source, Action<IMappingOperationOptions<object, TDestination>> opts) => Map(source, default, opts);
public TDestination Map<TDestination>(object source)
{
ArgumentNullException.ThrowIfNull(source);
Copy link
Member

Choose a reason for hiding this comment

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

Really? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha yes. We should be checking for nulls here when we rely on a not-null source object for getting the type.

@lbargaoanu
Copy link
Member

lbargaoanu commented Feb 7, 2024

This is not good :) If you don't want the headache, let's just revert the whole thing. We can simply be nullable oblivious as before.
Otherwise you have to ignore some cases (I'm not sure if there are others than a custom map) and apply the attribute on all overloads.

@AutoMapper AutoMapper deleted a comment from EklipZgit Feb 7, 2024
@AutoMapper AutoMapper locked and limited conversation to collaborators Feb 7, 2024
@jbogard
Copy link
Member Author

jbogard commented Feb 7, 2024

Then I'd just vote revert. I just tried this on a codebase and had similar headaches - it's not adding anything meaningful in the vast majority of cases.

This captures the vast majority of cases that I can think of, as well as our expected built-in behavior. You can get around all the compile-time null checks anyway but this is about describing expected behaviors. But it's not 100% accurate.

@lbargaoanu
Copy link
Member

It's not worth the trouble. We can simply revert and let people write their own stuff if they must.

@jbogard jbogard closed this Feb 7, 2024
@jbogard jbogard deleted the nullable-annotations-support branch February 7, 2024 21:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants