It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this
<FunctionKeys>
<Name>F13</Name>
<Name>F14</Name>
<Name>F15</Name>
<Name>F16</Name>
</FunctionKeys>
and So I want to take that data and put it back into my class.
This is in part what I have
public override void Load(string elementText)
{
var ele = XElement.Parse(elementText);
if (ele.Element("FunctionKeys").HasElements)
{
var funcs = ele.Element("FunctionKeys")
.Descendants("Name")
.Select(x=>x.Value)
.ToList();
foreach (string s in funcs)
{
dliUnit.FunctionKeyList.Add(
(System.Windows.Forms.Keys)System.Enum.Parse(typeof(System.Windows.Forms.Keys),
s));
}
}
}
Class to save to
public class DLIUnit
{
public List<Keys> FunctionKeyList
{
get;set;
}
//Other Members
}
Somethign about the way that I parse the string back to the Enum (well the entire process really) doesn't sit well with me. I'm very bad at LINQ but have been trying hard to learn it and use it more and more when I play with XML. Is there a better/cleaner way to parse the FunctionKeys?
EDIT
I forgot to mention that I can change any portion of the code or XML file. Right now this is a new idea and can be changed to make it better.