/// <summary>
        /// Composes a region based on the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>A region.</returns>
        private CodeItemRegion ComposeRegionForCodeItem(BaseCodeItem codeItem)
        {
            if (codeItem == null)
            {
                return(null);
            }

            var setting = MemberTypeSettingHelper.LookupByKind(codeItem.Kind);

            if (setting == null)
            {
                return(null);
            }

            var regionName = string.Empty;

            if (Settings.Default.Reorganizing_RegionsIncludeAccessLevel)
            {
                var element = codeItem as BaseCodeItemElement;
                if (element != null && (!Settings.Default.Reorganizing_RegionsIncludeAccessLevelForMethodsOnly || element is CodeItemMethod))
                {
                    var accessModifier = CodeElementHelper.GetAccessModifierKeyword(element.Access);
                    if (accessModifier != null)
                    {
                        regionName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(accessModifier) + " ";
                    }
                }
            }

            regionName += setting.EffectiveName;

            return(new CodeItemRegion {
                Name = regionName
            });
        }
Beispiel #2
0
        /// <summary>
        /// Recursively groups the children within the specified item based on their type.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        private static void RecursivelyGroupByType(ICodeItemParent codeItem)
        {
            // Skip any code item that is already a region or does not have children.
            if (codeItem.Kind == KindCodeItem.Region || !codeItem.Children.Any())
            {
                return;
            }

            // Capture the current children, then clear them out so they can be re-added.
            var children = codeItem.Children.ToArray();

            codeItem.Children.Clear();

            CodeItemRegion group      = null;
            int            groupOrder = -1;

            foreach (var child in children)
            {
                var memberTypeSetting = MemberTypeSettingHelper.LookupByKind(child.Kind);

                // Create a new group unless the right kind has already been defined.
                if (group == null || memberTypeSetting.Order != groupOrder)
                {
                    group = new CodeItemRegion {
                        Name = memberTypeSetting.EffectiveName, IsPseudoGroup = true
                    };

                    if (Settings.Default.Digging_TrackExpandedStateOfSpadeNodes)
                    {
                        group.IsExpanded = CodeItemRegionGlobals.GetIsExpandedFor(group.Name);
                    }

                    groupOrder = memberTypeSetting.Order;

                    codeItem.Children.Add(group);
                }

                // Add the child to the group and recurse.
                group.Children.Add(child);

                var childAsParent = child as ICodeItemParent;
                if (childAsParent != null)
                {
                    RecursivelyGroupByType(childAsParent);
                }
            }
        }