-
Notifications
You must be signed in to change notification settings - Fork 200
ConfigurationBinder Bind to support scalar value, added new Get<T> #282
Conversation
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.
nit: you should use named parameters when passing null
|
Looks good to me, @divega thoughts? |
|
Looks good in general. I have comments but I think they apply to the existing code even more than to the PR:
|
|
And regarding the last bullet on default values, what happens now if I ask for e.g. an int and:
(sorry if I am being too lazy to read the tests or try it 😄) |
|
@divega I can rename BindObject -> I thought its the best name because it is only binding all properties of the object which gets passed in. Regarding BindInstance, it ignores the object in case the method should return the value of a section already. And if the object passed in is null, it tries to instantiate it and then calls the different bind methods. This method does a lot of different stuff, maybe it could be refactored into multiple methods, or we just rename it. Any idea? Regarding the default values, I agree that this would be nice, but I guess this should be another PR and Task, right? |
I would suggest using
What about
Don't worry about that for now.
Agreed it should be a different PR. I will file a bunch of new bugs for these and some other concerns I have. |
|
@HaoK I fixed your PR comments and also added a few more unit tests
I actually found a bug in In general, if the value found is null, we will return
That's already being tested, There is still one possible null reference exception in the code which is if the |
Sounds good, however I would expect the public methods to throw if a null IConfiguration is passed at the start. Thoughts? |
|
Yup makes sense, should I add the [NotNull] attribute or check for null and throw an ArgumentException directly? |
|
Both. We don't know if we'll get to finish the code that auto-generates the checks based on the attribute. |
|
Ok that's done, too ;) |
|
Re [NotNull] my preference is to just use the attribute for new code which seems to be the pattern in most places. |
|
@HaoK actually you need to change your preference 😄 |
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.
Use nameof(configuration)
|
@divega Your comments are fixed, too |
|
Only minor thing is can we nuke the [NotNull] since we are removing them everywhere, lets not add more now |
New Get and Get<T> extension methods.
|
I removed the [NotNull] and squashed everything into one commit. Didn't merge yet, let me know if you want me to do that |
|
Looks good to me, merge away |
|
Thanks for your contribution @MichaCo! |
|
Hrm now we throw on Core: Microsoft.Framework.Configuration.Binder.Test.ConfigurationBinderTests.GetUri [FAIL] Microsoft.Framework.Configuration.Binder.Test.ConfigurationBinderTests.CanReadAllSupportedTypes(value: "http://www.bing.com", type: typeof(System.Uri)) [FAIL] |
|
I'll just disable these two new tests on core since it doesn't appear to be supported |
|
@divega welcome ;) |
Consider having sugar methods for type conversion of values in ConfigurationBinder #281