Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5056

Config.GetSection with invalid class property names

$
0
0

Using IConfigurationRoot extension method

public static T GetSectionAsObject<T>(this IConfigurationRoot configuration, string key){    return configuration.GetSection(key).Get<T>();}

I am retrieving sections from configuration file as objects.For example I have a section in configuration file:

"RandomClass": {"Attribute1": "x","Attribute2": y,"Attribute3": "z"  },

which gets mapped to an object of class RandomClassSettings

public class RandomClassSettings    {        public string Attribute1 { get; set; }        public string Attribute2 { get; set; }        public string Attribute3 { get; set; }    }

This works.

Unfortunately, in the configuration file I have another section with a key "attribue.RandomAttribue" which won't get mapped to object like in the previous example because of the "." in it's name. Any ideas how to make it possible? I can't rename the key in configuration file.

I tried making another class Attribute and having a class like below, but it doesn't work either.

public class NewClassSettings {        public Attribute attribute { get; set; }    }

Viewing all articles
Browse latest Browse all 5056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>