Ejemplo n.º 1
0
 public static bool SettingsEqual(SettingsPageBase a, SettingsPageBase b)
 {
     if (a.GetType() != b.GetType())
     {
         return(false);
     }
     foreach (PropertyInfo prop in a.GetType().GetProperties())
     {
         foreach (SettingsKeyAttribute attr in prop.GetCustomAttributes(typeof(SettingsKeyAttribute), true))
         {
             object vala = prop.CallGet(a), valb = prop.CallGet(b);
             if (!Object.Equals(vala, valb))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
 public static void CopySettingsPage(SettingsPageBase fromPage, SettingsPageBase toPage)
 {
     foreach (PropertyInfo prop in fromPage.GetType().GetProperties())
     {
         foreach (SettingsKeyAttribute attr in prop.GetCustomAttributes(typeof(SettingsKeyAttribute), true))
         {
             prop.CallSet(toPage, prop.CallGet(fromPage));
         }
     }
 }
Ejemplo n.º 3
0
 public static void LoadSettingsPage(SettingsPageBase page, XmlElement xml)
 {
     foreach (PropertyInfo prop in page.GetType().GetProperties())
     {
         foreach (SettingsKeyAttribute attr in prop.GetCustomAttributes(typeof(SettingsKeyAttribute), true))
         {
             XmlElement node = xml.SelectSingleNode(String.Format("Param[@name=\"{0}\"]", attr.KeyName)) as XmlElement;
             if (node != null)
             {
                 object value = XmlTool.ValueFromString(prop.PropertyType, node.GetAttribute("value"));
                 prop.CallSet(page, value);
             }
         }
     }
 }
Ejemplo n.º 4
0
 public static void SaveSettingsPage(SettingsPageBase page, SettingsPageBase pageBase, XmlElement xml)
 {
     foreach (PropertyInfo prop in page.GetType().GetProperties())
     {
         foreach (SettingsKeyAttribute attr in prop.GetCustomAttributes(typeof(SettingsKeyAttribute), true))
         {
             object myvalue = prop.CallGet(page), baseValue = null;
             if (pageBase != null)
             {
                 baseValue = prop.CallGet(pageBase);
             }
             if (myvalue != null && (baseValue == null || !myvalue.Equals(baseValue)))
             {
                 XmlElement parx = xml.AddChild("Param");
                 parx.SetAttribute("name", attr.KeyName);
                 parx.SetAttribute("value", XmlTool.ValueToString(prop.PropertyType, myvalue));
             }
         }
     }
 }