Exemple #1
0
        /// <summary>
        /// Resets the settings instance to the default values for that instance.
        /// </summary>
        /// <param name="settingsInstance">The instance of the object to be reset</param>
        /// <returns>Returns the instance of the new object with default values.</returns>
        public static SettingsBase ResetSettingsInstance(SettingsBase settingsInstance)
        {
            string       id     = settingsInstance.ID;
            SettingsBase newObj = (SettingsBase)Activator.CreateInstance(settingsInstance.GetType());

            newObj.ID           = id;
            AllSettingsDict[id] = newObj;
            return(newObj);
        }
Exemple #2
0
        /// <summary>
        /// Resets the settings instance to the default values for that instance.
        /// </summary>
        /// <param name="settingsInstance">The instance of the object to be reset</param>
        /// <returns>Returns the instance of the new object with default values.</returns>
        public static SettingsBase ResetSettingsInstance(SettingsBase settingsInstance)
        {
            if (settingsInstance == null)
            {
                throw new ArgumentNullException(nameof(settingsInstance));
            }
            string       id     = settingsInstance.ID;
            SettingsBase newObj = (SettingsBase)Activator.CreateInstance(settingsInstance.GetType());

            newObj.ID           = id;
            AllSettingsDict[id] = newObj;
            return(newObj);
        }
Exemple #3
0
        internal static List <SettingPropertyGroup> GetSettingPropertyGroups(this SettingsBase sb)
        {
            var groups = new List <SettingPropertyGroup>();
            // Find all the properties in the settings instance which have the SettingProperty attribute.
            var propList = (from p in sb.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                            let propAttr = p.GetCustomAttribute <SettingPropertyAttribute>(true)
                                           let groupAttr = p.GetCustomAttribute <SettingPropertyGroupAttribute>(true)
                                                           where propAttr != null
                                                           let groupAttrToAdd = groupAttr ?? SettingPropertyGroupAttribute.Default
                                                                                select new SettingProperty(propAttr, groupAttrToAdd, p, sb)).ToList();

            //Loop through each property
            foreach (var settingProp in propList)
            {
                //First check that the setting property is set up properly.
                CheckIsValid(settingProp);
                //Find the group that the setting property should belong to. This is the default group if no group is specifically set with the SettingPropertyGroup attribute.
                SettingPropertyGroup group = GetGroupFor(settingProp, groups);
                group.Add(settingProp);
            }

            //If there is more than one group in the list, remove the misc group so that it can be added to the bottom of the list after sorting.
            SettingPropertyGroup miscGroup = GetGroupFor(SettingPropertyGroupAttribute.DefaultGroupName, groups);

            if (miscGroup != null && groups.Count > 1)
            {
                groups.Remove(miscGroup);
            }
            else
            {
                miscGroup = null;
            }

            //Sort the list of groups alphabetically.
            groups.Sort((x, y) => x.GroupName.CompareTo(y.GroupName));
            if (miscGroup != null)
            {
                groups.Add(miscGroup);
            }

            foreach (var group in groups)
            {
                group.SetParentGroup(null);
            }

            return(groups);
        }