c# - How to Read a Configuration Section from XML in a Database? -
i have config class this:
public class myconfig : configurationsection { [configurationproperty("myproperty", isrequired = true)] public string myproperty { { return (string)this["myproperty"]; } set { this["myproperty"] = value; } } } and being instantiated class this
(myconfig)configurationmanager.getsection("myconfig") we making changes , storing configuration file in db xml, in config file.
i maintain myconfig configurationsection backwards compatibility still able instantiate using xml string retrieved db.
is possible? if so, how? (keep in mind should still work instantiated above)
my suggestion keep current myconfig class load xml database in constructor, in each property of myconfig, can put in logic determine value (either database or .config file) if need pull config either location, or have fall if value empty.
public class myconfig : configurationsection { public myconfig() { // throw code in here retrieve xml database // deserialize xml , store _myproperty = "<deserialized value db>"; } private string _myproperty = string.empty; [configurationproperty("myproperty", isrequired = true)] public string myproperty { { if (_myproperty != null && _myproperty.length > 0) return _myproperty; else return (string)this["myproperty"]; } set { this["myproperty"] = value; } } }
Comments
Post a Comment