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

Unclear doc or signature for ConfigurationBinder.GetValue<T>(...) which returns a default #9638

Open
MashalMohammed opened this issue Feb 25, 2024 · 1 comment · May be fixed by #9639
Open
Labels
area-Extensions-Configuration Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner

Comments

@MashalMohammed
Copy link

MashalMohammed commented Feb 25, 2024

ConfigurationBinder.GetValue<T>(...) returns null if the specified key is not found in the IConfiguration, which is not apparent or documented. Sibling variant methods has a default value param at the least.

namespace Microsoft.Extensions.Configuration
{
    /// <summary>
    /// Static helper class that allows binding strongly typed objects to configuration values.
    /// </summary>
    public static class [ConfigurationBinder]
    {
    
        ...
    
        /// <summary>
        /// Extracts the value with the specified key and converts it to type T.
        /// </summary>
        /// <typeparam name="T">The type to convert the value to.</typeparam>
        /// <param name="configuration">The configuration.</param>
        /// <param name="key">The key of the configuration section's value to convert.</param>
        /// <param name="defaultValue">The default value to use if no value is found.</param>
        /// <returns>The converted value.</returns>
        public static T? GetValue<T>(this IConfiguration configuration, string key, T defaultValue)
        {
            return (T?)GetValue(configuration, typeof(T), key, defaultValue);
        }

https://source.dot.net/#Microsoft.Extensions.Configuration.Binder/ConfigurationBinder.cs,232ab46b757d72f9

Corresponding changes: #9639

@issues-automation issues-automation bot added the Pri3 Indicates issues/PRs that are low priority label Feb 25, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 25, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 25, 2024
@MihaZupan MihaZupan added area-Extensions-Configuration and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Configuration Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner
Projects
None yet
2 participants