I am using C# with the .NET 3.5 framework to write an application.
I have an enum like this,
public static enum SettingOneType { FooA, FooB, FooC }
I also have an XDocument that I load like this in a Load() method,
LoadXML(){
...
XDocument SettingsDocument;
if(File.Exists(path)
{
XElement SettingsElement = new XElement("DeviceSettings",
new XElement("Setitng1", SettingOneType.FooA.ToString()),
new XElement("Setting2", ... ));
XDeclaration dec = new XDeclaration("1.0", "UTF-8", "yes");
SettingsDocument = new XDocument(dec, SettingsElement);
SettingsDocument.Save(xpath);
}
else SettingsDocument = XDocument.Load(path);
}
What I am wondering is, is there a way to read these settings in a strongly typed manner. Because I want to have a Property in my application that will access the value in the xml file like this...
public SettingOneType SettingOne
{
get{
SettingOneType x = SettingsDocument. //Here I know I can use LINQ statements to file the value I want but is there a way to cast the value to the correct type without using a giant switch statement or something?
}
}
NOTE: Before someone suggests that I use the built in Application Settings files that are available with .NET, don't bother. I usually do use those but for this project there is a reason that I can't that I don't want to explain.