예제 #1
0
        public static History Load()
        {
            History     history     = new History();
            XmlDocument xmlDocument = new XmlDocument();

            if (File.Exists(History.xmlPath))
            {
                try
                {
                    xmlDocument.Load(History.xmlPath);
                    XmlNode        xmlNode    = xmlDocument.SelectSingleNode("Config");
                    PropertyInfo[] properties = history.GetType().GetProperties();
                    for (int i = 0; i < properties.Length; i++)
                    {
                        PropertyInfo propertyInfo = properties[i];
                        string       value        = xmlNode.SelectSingleNode(propertyInfo.Name).Attributes["value"].Value;
                        if (propertyInfo.PropertyType.IsEnum)
                        {
                            propertyInfo.SetValue(history, Enum.Parse(propertyInfo.PropertyType, value), null);
                        }
                        else
                        {
                            propertyInfo.SetValue(history, value, null);
                        }
                    }
                }
                catch (Exception)
                {
                    History.Save(history);
                }
            }
            else
            {
                History.Save(history);
            }
            return(history);
        }
예제 #2
0
        public static History Load()
        {
            History     sys = new History();
            XmlDocument xml = new XmlDocument();

            if (File.Exists(xmlPath))
            {
                try
                {
                    xml.Load(xmlPath);
                    XmlNode root = xml.SelectSingleNode("Config");

                    foreach (PropertyInfo item in sys.GetType().GetProperties())
                    {
                        string v = root.SelectSingleNode(item.Name).Attributes["value"].Value;
                        if (item.PropertyType.IsEnum)
                        {
                            item.SetValue(sys, Enum.Parse(item.PropertyType, v), null);
                        }
                        else
                        {
                            item.SetValue(sys, v, null);
                        }
                    }
                }
                catch (Exception)
                {
                    Save(sys);
                }
            }
            else
            {
                Save(sys);
            }

            return(sys);
        }