ChrisMissal / Formo

Formo allows you to use your configuration file as a dynamic object. Turn your web.config or application settings into a rich, dynamic object.
http://chrismissal.com/Formo/
MIT License
259 stars 33 forks source link

I get null for key "part1.part2.part3" - or how do you handle periods? #37

Closed stephendmorrison closed 9 years ago

stephendmorrison commented 9 years ago

Hi Team,

Love your product by the way.

Just one little issue. I am trying to read in a section where I am have no control over the key names in it and the key names have periods e.g. "part1.part2" when I try to read the value I get null.

This section is a name value collection custom section

< mySection > < add key="allofit" value="wholekey" /> < add key="part1.part2" value="dividedkey" /> < /mySection >

The following code attempts to read it

        dynamic mySection = new Configuration("mySection");
        var allofit = quartzSection.allofit;
        var dividedKey2 = quartzSection.part1_part2;  // returns null
        var dividedKey3 = quartzSection.part1part2; // returns null
        //var dividedKey1 = quartzSection.part1.part2; -- causes runtime error

Is this simply a no-go area and all keys must be alphanumeric or is this support for this and I just couldn't find it.

Any help appreciated

Stephen

onliner10 commented 9 years ago

Hi, Have you tried using Get(string key) method ? I believe it should solve your problem

ChrisMissal commented 9 years ago

Hi @stephendmorrison, thanks!

Unfortunately the chaining is a no-go right now, and @onliner10 has the correct solution. Your example above would have to look like this:

dynamic quartzSection = new Configuration("quartzSection");
var key = quartzSection.Get("part1.part2");
stephendmorrison commented 9 years ago

That's great. I didn't see that feature in the docs. Just what I needed. Thanks guys!