コード例 #1
0
        private PropertyGroup AddAndReturnPropertyGroup(string name)
        {
            // ensure we don't have it already
            if (PropertyGroups.Any(x => x.Name == name))
            {
                return(null);
            }

            // create the new group
            var group = new PropertyGroup {
                Name = name, SortOrder = 0
            };

            // check if it is inherited - there might be more than 1 but we want the 1st, to
            // reuse its sort order - if there are more than 1 and they have different sort
            // orders... there isn't much we can do anyways
            var inheritGroup = CompositionPropertyGroups.FirstOrDefault(x => x.Name == name);

            if (inheritGroup == null)
            {
                // no, just local, set sort order
                var lastGroup = PropertyGroups.LastOrDefault();
                if (lastGroup != null)
                {
                    group.SortOrder = lastGroup.SortOrder + 1;
                }
            }
            else
            {
                // yes, inherited, re-use sort order
                group.SortOrder = inheritGroup.SortOrder;
            }

            // add
            PropertyGroups.Add(group);

            return(group);
        }