Пример #1
0
        protected override void ExecuteInternal()
        {
            ITypeDeclaration declaration = GetTypeDeclaration();
            Assert.CheckNotNull(declaration);

            List<IGroupingOption> options = new List<IGroupingOption>();

            options.Add(new PredicateGrouping(declaration, "Delegates", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IDelegateDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Types", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is ITypeDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Fields", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IFieldDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Events", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IEventDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Constructors", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IConstructorDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Properties", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IPropertyDeclaration;
                                                                               }));

            options.Add(new PredicateGrouping(declaration, "Methods", delegate(ITypeMemberDeclaration obj)
                                                                               {
                                                                                   return obj is IMethodDeclaration;
                                                                               }));

            // TODO add other groping fore move from regions

            RegionDecorator regionDecorator = new RegionDecorator(declaration.ToTreeNode());

            using (WriteLockCookie cookie = WriteLockCookie.Create())
            {
                IList<ITypeMemberDeclaration> declarations = declaration.MemberDeclarations;
                foreach (ITypeMemberDeclaration memberDeclaration in declarations)
                {
                    foreach (IGroupingOption option in options)
                    {
                        if (option.IsAccept(memberDeclaration))
                            break;
                    }
                }

                foreach (IGroupingOption option in options)
                {
                    option.Execute();
                }
            }
        }
Пример #2
0
        protected override void ExecuteInternal()
        {
            ITypeDeclaration declaration = GetTypeDeclaration();
            Assert.CheckNotNull(declaration);

            List<IGroupingOption> options = new List<IGroupingOption>();

            options.Add(new PredicateGrouping(declaration, DELEGATES, delegate(ITypeMemberDeclaration obj)
                                                                          {
                                                                              return obj is IDelegateDeclaration;
                                                                          }));

            options.Add(new PredicateGrouping(declaration, TYPES, delegate(ITypeMemberDeclaration obj)
                                                                      {
                                                                          return obj is ITypeDeclaration;
                                                                      }));

            options.Add(new PredicateGrouping(declaration, FIELDS, delegate(ITypeMemberDeclaration obj)
                                                                       {
                                                                           return obj is IFieldDeclaration;
                                                                       }));

            options.Add(new PredicateGrouping(declaration, EVENTS, delegate(ITypeMemberDeclaration obj)
                                                                       {
                                                                           return obj is IEventDeclaration;
                                                                       }));

            options.Add(new PredicateGrouping(declaration, CONSTRUCTORS, delegate(ITypeMemberDeclaration obj)
                                                                             {
                                                                                 return obj is IConstructorDeclaration;
                                                                             }));

            options.Add(new PredicateGrouping(declaration, PROPERTIES, delegate(ITypeMemberDeclaration obj)
                                                                           {
                                                                               return obj is IPropertyDeclaration;
                                                                           }));
            //
            //            options.Add(new PredicateGrouping(declaration, HANDLERS, delegate(ITypeMemberDeclaration obj)
            //                                                                         {
            //                                                                             IMethodDeclaration methodDeclaration = obj as IMethodDeclaration;
            //                                                                             if (methodDeclaration == null)
            //                                                                                 return false;
            //
            //                                                                             IList<IRegularParameterDeclaration> parameters = methodDeclaration.ParameterDeclarations;
            //                                                                             if (parameters == null)
            //                                                                                 return false;
            //
            //                                                                             if (parameters.Count != 2)
            //                                                                                 return false;
            //
            //
            //
            //                                                                        }));

            options.Add(new PredicateGrouping(declaration, METHODS, delegate(ITypeMemberDeclaration obj)
                                                                        {
                                                                            return obj is IMethodDeclaration;
                                                                        }));

            RegionDecorator regionDecorator = new RegionDecorator(declaration.ToTreeNode());

            using (WriteLockCookie cookie = WriteLockCookie.Create())
            {
                // grouping

                IList<ITypeMemberDeclaration> declarations = declaration.MemberDeclarations;
                foreach (ITypeMemberDeclaration memberDeclaration in declarations)
                {
                    foreach (IGroupingOption option in options)
                    {
                        if (option.IsAccept(memberDeclaration))
                            break;
                    }
                }

                foreach (IGroupingOption option in options)
                {
                    option.Execute();
                }

                // reordering
                List<string> orderedRegionTypes = new List<string>();
                orderedRegionTypes.Add(DELEGATES);
                orderedRegionTypes.Add(TYPES);
                orderedRegionTypes.Add(FIELDS);
                orderedRegionTypes.Add(EVENTS);
                orderedRegionTypes.Add(CONSTRUCTORS);
                orderedRegionTypes.Add(PROPERTIES);
                orderedRegionTypes.Add(METHODS);
                orderedRegionTypes.Add(HANDLERS);

                Assert.Check(orderedRegionTypes.Count == options.Count);

                ReorderRegions reorderRegions = new ReorderRegions(declaration, orderedRegionTypes);

                reorderRegions.Reorder();

            }
        }