示例#1
0
 private SettingPropertyGroup GetGroupForRecursive(string groupName, ICollection <SettingPropertyGroup> groupsList, SettingProperty sp)
 {
     if (groupName.Contains(SubGroupDelimiter))
     {
         //Need to go deeper
         string topGroupName           = GetTopGroupName(groupName, out string truncatedGroupName);
         SettingPropertyGroup topGroup = GetGroupFor(topGroupName, groupsList);
         if (topGroup == null)
         {
             topGroup = new SettingPropertyGroup(sp.GroupAttribute, topGroupName);
             groupsList.Add(topGroup);
         }
         return(GetGroupForRecursive(truncatedGroupName, topGroup.SettingPropertyGroups, sp));
     }
     else
     {
         //Reached the bottom level, can return the final group.
         SettingPropertyGroup group = groupsList.GetGroup(groupName);
         if (group == null)
         {
             group = new SettingPropertyGroup(sp.GroupAttribute, groupName);
             groupsList.Add(group);
         }
         return(group);
     }
 }
示例#2
0
        private SettingPropertyGroup GetGroupFor(SettingProperty sp, List <SettingPropertyGroup> groupsList)
        {
            if (sp.GroupAttribute == null)
            {
                throw new Exception($"SettingProperty {sp.Name} has null GroupAttribute");
            }

            SettingPropertyGroup group = groupsList.Where((x) => x.GroupName == sp.GroupAttribute.GroupName).FirstOrDefault();

            if (group == null)
            {
                group = new SettingPropertyGroup(sp.GroupAttribute);
                groupsList.Add(group);
            }
            return(group);
        }
示例#3
0
        public List <SettingPropertyGroup> GetSettingPropertyGroups()
        {
            var groups = new List <SettingPropertyGroup>();
            // Find all the properties in the settings instance which have the SettingProperty attribute.
            var propList = (from p in 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, this)).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(SettingPropertyGroup.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);
        }
示例#4
0
        public List <SettingPropertyGroup> GetSettingPropertyGroups()
        {
            var groups = new List <SettingPropertyGroup>();

            var propList = (from p in 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 == null ? SettingPropertyGroupAttribute.Default : groupAttr
                                                                                select new SettingProperty(propAttr, groupAttrToAdd, p, this)).ToList();


            foreach (var settingProp in propList)
            {
                CheckIsValid(settingProp);
                SettingPropertyGroup group = GetGroupFor(settingProp, groups);
                group.Add(settingProp);
            }

            SettingPropertyGroup noneGroup = GetGroupFor(groups, SettingPropertyGroup.DefaultGroupName);

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

            groups.Sort((x, y) => x.GroupName.CompareTo(y.GroupName));
            if (noneGroup != null)
            {
                groups.Add(noneGroup);
            }

            return(groups);
        }
示例#5
0
        private SettingPropertyGroup GetGroupFor(SettingProperty sp, ICollection <SettingPropertyGroup> groupsList)
        {
            //If the setting somehow doesn't have a group attribute, throw an error.
            if (sp.GroupAttribute == null)
            {
                throw new Exception($"SettingProperty {sp.Name} has null GroupAttribute");
            }

            SettingPropertyGroup group;

            //Check if the intended group is a sub group
            if (sp.GroupAttribute.GroupName.Contains(SubGroupDelimiter))
            {
                //Intended group is a sub group. Must find it. First get the top group.
                string truncatedGroupName;
                string topGroupName           = GetTopGroupName(sp.GroupAttribute.GroupName, out truncatedGroupName);
                SettingPropertyGroup topGroup = groupsList.GetGroup(topGroupName);
                if (topGroup == null)
                {
                    topGroup = new SettingPropertyGroup(sp.GroupAttribute, topGroupName);
                    groupsList.Add(topGroup);
                }
                //Find the sub group
                group = GetGroupForRecursive(truncatedGroupName, topGroup.SettingPropertyGroups, sp);
            }
            else
            {
                //Group is not a subgroup, can find it in the main list of groups.
                group = groupsList.GetGroup(sp.GroupAttribute.GroupName);
                if (group == null)
                {
                    group = new SettingPropertyGroup(sp.GroupAttribute);
                    groupsList.Add(group);
                }
            }
            return(group);
        }