Data.HotkeysData.ReadElement C# (CSharp) Method

ReadElement() private static method

private static ReadElement ( System.Xml.Linq.XContainer root, string element, bool readAlt ) : ModifierKeys>?.KeyValuePair
root System.Xml.Linq.XContainer
element string
readAlt bool
return ModifierKeys>?.KeyValuePair
        private static KeyValuePair<Keys, ModifierKeys>? ReadElement(XContainer root, string element, bool readAlt)
        {
            try
            {
                var query = from hotkeys in root.Descendants(element)
                    select hotkeys.Element("key");
                Keys key;
                var xelements = query as XElement[] ?? query.ToArray();
                var keyValue = xelements.First().Value;
                keyValue = char.ToUpper(keyValue[0]) + keyValue.Substring(1);
                if (!Enum.TryParse(keyValue, out key))
                {
                    var message = LP.Unable_to_get_key_from_string + " " + keyValue + ". "+LP.Your_hotkeys_xml_file_is_invalid;
                    MessageBox.Show(message);
                    return null;
                }

                var shiftQuery = from hotkeys in root.Descendants(element)
                    select hotkeys.Element("shift");
                var ctrlQuery = from hotkeys in root.Descendants(element)
                    select hotkeys.Element("ctrl");
                var windowQuery = from hotkeys in root.Descendants(element)
                    select hotkeys.Element("window");
                bool alt = false, shift, ctrl, window;
                bool.TryParse(shiftQuery.First().Value, out shift);
                bool.TryParse(ctrlQuery.First().Value, out ctrl);
                bool.TryParse(windowQuery.First().Value, out window);
                if (readAlt)
                {
                    var altQuery = from hotkeys in root.Descendants(element)
                        select hotkeys.Element("alt");
                    bool.TryParse(altQuery.First().Value, out alt);
                }

                var modifier = ConvertToModifierKey(ctrl, alt, shift, window);
                return new KeyValuePair<Keys, ModifierKeys>(key, modifier);
            }
            catch
            {
                return null;
            }
        }