Пример #1
0
        //void importValues(Settings s)!!!Declined because such copying may bring to a mess in the object's state (if any)
        //{
        //    foreach (FieldInfo settingsTypeFieldInfo in GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
        //        settingsTypeFieldInfo.SetValue(this, settingsTypeFieldInfo.GetValue(s));
        //}

        /// <summary>
        /// Replaces the value of the field defined by __Info with a new object initiated with the default values.
        /// Tries to load it from the initial file located in the app's directory.
        /// If this file does not exist, it creates an object with the hardcoded values.
        /// (!)Calling this method on a detached Settings object throws an exception because otherwise it would lead to a confusing effect.
        /// </summary>
        public void Reset(/*bool ignoreInitFile = false*/)
        {
            if (!IsAttached())//while technically it is possible, it is a way of confusion: called on one object it would replace another one!
            {
                throw new Exception("This method cannot be performed on this Settings object because it is not attached to its Settings field (" + __Info?.Type + ")");
            }
            __Info.SetObject(Create(__Info, true, true));
        }
Пример #2
0
        /// <summary>
        /// Can be used to initialize an optional Settings field.
        /// </summary>
        /// <param name="settingsFieldFullName">full name of Settings field; it equals to the name of its storage file without extention</param>
        /// <param name="throwExceptionIfCouldNotLoadFromStorageFile"></param>
        public static void Reload(string settingsFieldFullName, bool throwExceptionIfCouldNotLoadFromStorageFile = false)
        {
            SettingsMemberInfo sfi = GetSettingsFieldInfo(settingsFieldFullName);
            Settings           s   = Settings.Create(sfi, false, throwExceptionIfCouldNotLoadFromStorageFile);

            sfi.SetObject(s);
        }
Пример #3
0
        //// ???what would it be needed for?
        //public static S CreateResetInstance<S>(string settingsFieldFullName) where S : Settings, new()
        //{
        //    return (S)Settings.Create(GetSettingsFieldInfo(settingsFieldFullName), true, true);
        //}

        //// ???what would it be needed for?
        //public static S CreateReloadedInstance<S>(string settingsFieldFullName, bool throwExceptionIfCouldNotLoadFromStorageFile = false) where S : Settings, new()
        //{
        //    return (S)Settings.Create(GetSettingsFieldInfo(settingsFieldFullName), false, throwExceptionIfCouldNotLoadFromStorageFile);
        //}

        /// <summary>
        /// Can be used to initialize an optional Settings field.
        /// </summary>
        /// <param name="settingsFieldFullName">full name of Settings field; it equals to the name of its storage file without extention</param>
        public static void Reset(string settingsFieldFullName)
        {
            SettingsMemberInfo sfi = GetSettingsFieldInfo(settingsFieldFullName);
            Settings           s   = Settings.Create(sfi, true, true);

            sfi.SetObject(s);
        }