-
Notifications
You must be signed in to change notification settings - Fork 764
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
Add AdditionalPropertiesDictionary.TryGetValue<T> #5528
Add AdditionalPropertiesDictionary.TryGetValue<T> #5528
Conversation
src/Libraries/Microsoft.Extensions.AI.Abstractions/AdditionalPropertiesDictionary.cs
Outdated
Show resolved
Hide resolved
/// If a non-<see langword="null"/> is found for the key in the dictionary, but the value is not of the requested type but is | ||
/// an <see cref="IConvertible"/> object, the method will attempt to convert the object to the requested type. | ||
/// </remarks> | ||
public bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explicitly ban nullable type parameters?
public bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value) | |
public bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value) where T : notnull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does that help? The parameter is already nullable in the case of reference types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It explicitly prevents passing nullable type parameters even if it doesn't change the nullability of the out parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but what benefit does that provide here? What errors does it avoid? It seems like it'd only be a hindrance here, eg not being able to use this in a method with an unconstrained T. This T is only ever in an out position, and the out is already nullable regardless of the T.
Fixes #5526
Microsoft Reviewers: Open in CodeFlow