-
Notifications
You must be signed in to change notification settings - Fork 203
Helper to enumerate IConfiguration? #370
Comments
Looks good!
Curious, do you see this as something many customers will need to do or as a rather advanced scenario? FWIW, we could have had |
Yes, see aspnet/Hosting#582 where I ran into this. |
I added the suggested enumeration as an extension method as part of aspnet/Hosting#596. Once it is implemented in Configuration, I'll remove the redundant extension in Hosting. |
@JunTaoLuo Yes I was looking at it this second. Thanks for the heads up. @HaoK Let's have this as a public extension method in Configuration (it could live side-byside with the
etc. |
I like |
@divega What GetValue stuff? The ones that live in the binder? or did you want me to move those to Configuration now as part of adding Flatten? |
I was referring to having this as an extension method in configuration alongside I am not sure about the naming. Of the three options I wrote down I think |
Well GetFlattenedSettings doesn't really make sense given the current config apis which don't use the term settings anywhere. I don't really think ToKeyValuePairs actually is very clear compared to something with the word Flatten in it. Since this is just a DepthFirstTraversal, maybe that makes it clear?
|
Actually why can't we just call this Enumerate? |
I am not completely against any of these names besides probably the "depth first" ones, as I don't think the fact that is depth first is going to play much of a role 😄 Thinking of |
Well known terms (from linq) are ToList, ToArray, ToDictionary or AsEnumerable. |
I like AsEnumerable as well |
We could do both of those actually ToDictionary/AsEnumerable |
👍 |
Having var dictionary = configuration.AsEnumerable().ToDictionary(p => p.Key, x => p.Value); So I don't think we would need to add |
So why don't we just make IConfiguration extend IEumerable instead of adding an AsEnumerable?
|
Mostly because it would automatically pollute our nice API with several dozen LINQ operators 😄 See my previous comment at #370 (comment). |
I was trying to copy an
IConfiguration
into a flat dicitonary and came up with this (completely untested) method:It would be useful to have something that expanded all of the kvps without doing manual recursion.
/cc @divega @HaoK
The text was updated successfully, but these errors were encountered: