Esempio n. 1
0
 /// <summary>Laden der Settings</summary>
 public void load()
 {
     if (System.IO.File.Exists(iniFilename))
     {
         foreach (PropertyInfo property in this.GetType().GetProperties())
         {
             Boolean canNext                = false;
             String  groupName              = "Main";
             String  propertyName           = property.Name;
             String  defString              = null;
             DefaultValueAttribute defValue = (DefaultValueAttribute)Attribute.GetCustomAttribute(property, typeof(DefaultValueAttribute));
             if (defValue != null)
             {
                 ClassConverters.getStringFromValue(defValue.Value, property.PropertyType, out defString);
             }
             INIIgnoreThis ignorePropAttrib = (INIIgnoreThis)Attribute.GetCustomAttribute(property, typeof(INIIgnoreThis));
             if (ignorePropAttrib == null)
             {
                 canNext = true;
             }
             else
             {
                 canNext = !ignorePropAttrib.IgnoreThis;
             }
             if (canNext)
             {
                 INIGroupName groupNameAttrib = (INIGroupName)Attribute.GetCustomAttribute(property, typeof(INIGroupName));
                 if (groupNameAttrib != null)
                 {
                     groupName = groupNameAttrib.GName;
                 }
                 INIPropertyName propertyNameAttrib = (INIPropertyName)Attribute.GetCustomAttribute(property, typeof(INIPropertyName));
                 if (propertyNameAttrib != null)
                 {
                     propertyName = propertyNameAttrib.Name;
                 }
                 String loadedValue = readStringFromIni(groupName, propertyName, defString);
                 Object setObject   = null;
                 if (ClassConverters.getValueFromString(loadedValue, property.PropertyType, out setObject))
                 {
                     property.SetValue(this, setObject, null);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>Speichern der Settings</summary>
        public void save()
        {
            foreach (PropertyInfo property in this.GetType().GetProperties())
            {
                Boolean       canNext          = false;
                String        groupName        = "Main";
                String        propertyName     = property.Name;
                INIIgnoreThis ignorePropAttrib = (INIIgnoreThis)Attribute.GetCustomAttribute(property, typeof(INIIgnoreThis));
                if (ignorePropAttrib == null)
                {
                    canNext = true;
                }
                else
                {
                    canNext = !ignorePropAttrib.IgnoreThis;
                }
                if (canNext)
                {
                    String saveValue = null;
                    ClassConverters.getStringFromValue(property.GetValue(this, null), property.PropertyType, out saveValue);

                    INIGroupName groupNameAttrib = (INIGroupName)Attribute.GetCustomAttribute(property, typeof(INIGroupName));
                    if (groupNameAttrib != null)
                    {
                        groupName = groupNameAttrib.GName;
                    }

                    INIPropertyName propertyNameAttrib = (INIPropertyName)Attribute.GetCustomAttribute(property, typeof(INIPropertyName));
                    if (propertyNameAttrib != null)
                    {
                        propertyName = propertyNameAttrib.Name;
                    }

                    WritePrivateProfileString(groupName, propertyName, saveValue, iniFilename);
                }
            }
        }