DoGlobalOperationOn() public method

public DoGlobalOperationOn ( IEnumerable entities, Action callback, string operationDescription = null ) : void
entities IEnumerable
callback Action
operationDescription string
return void
コード例 #1
0
            static void ExecuteScriptToFixStaticMethodIssue(Script script,
                                                            BaseRefactoringContext context,
                                                            AstNode methodDeclaration)
            {
                var clonedDeclaration = (MethodDeclaration)methodDeclaration.Clone();

                clonedDeclaration.Modifiers |= Modifiers.Static;
                script.Replace(methodDeclaration, clonedDeclaration);
                var rr = context.Resolve(methodDeclaration) as MemberResolveResult;

                //var method = (IMethod)rr.Member;
                //method.ImplementedInterfaceMembers.Any(m => methodGroupResolveResult.Methods.Contains((IMethod)m));

                script.DoGlobalOperationOn(rr.Member,
                                           (fctx, fscript, fnode) => {
                    DoStaticMethodGlobalOperation(fnode, fctx, rr, fscript);
                });
            }
コード例 #2
0
            void Fix(Script script, MethodDeclaration methodDeclaration, TypeDeclaration typeDeclaration)
            {
                var newTypeDeclaration = (TypeDeclaration)typeDeclaration.Clone();

                var resolver = ctx.GetResolverStateAfter(typeDeclaration.LBraceToken);

                var  typeResolve           = resolver.ResolveSimpleName("IDisposable", new List <IType>()) as TypeResolveResult;
                bool canShortenIDisposable = typeResolve != null && typeResolve.Type.FullName == "System.IDisposable";

                string interfaceName = (canShortenIDisposable ? string.Empty : "System.") + "IDisposable";

                newTypeDeclaration.BaseTypes.Add(new SimpleType(interfaceName));

                foreach (var method in DisposeMethods(newTypeDeclaration).ToList())
                {
                    if (typeDeclaration.ClassType == ClassType.Interface)
                    {
                        method.Remove();
                    }
                    else
                    {
                        method.Modifiers &= ~Modifiers.Private;
                        method.Modifiers &= ~Modifiers.Protected;
                        method.Modifiers &= ~Modifiers.Internal;
                        method.Modifiers |= Modifiers.Public;
                    }
                }

                if (typeDeclaration.ClassType == ClassType.Interface)
                {
                    var disposeMember = ((MemberResolveResult)ctx.Resolve(methodDeclaration)).Member;
                    script.DoGlobalOperationOn(new List <IEntity>()
                    {
                        disposeMember
                    }, (nCtx, nScript, nodes) => {
                        List <Tuple <AstType, AstType> > pendingChanges = new List <Tuple <AstType, AstType> >();
                        foreach (var node in nodes)
                        {
                            var method = node as MethodDeclaration;
                            if (method != null && !method.PrivateImplementationType.IsNull)
                            {
                                var nResolver = ctx.GetResolverStateAfter(typeDeclaration.LBraceToken);

                                var nTypeResolve            = nResolver.ResolveSimpleName("IDisposable", new List <IType>()) as TypeResolveResult;
                                bool nCanShortenIDisposable = nTypeResolve != null && nTypeResolve.Type.FullName == "System.IDisposable";

                                string nInterfaceName = (nCanShortenIDisposable ? string.Empty : "System.") + "IDisposable";

                                pendingChanges.Add(Tuple.Create(method.PrivateImplementationType, AstType.Create(nInterfaceName)));
                            }
                        }

                        foreach (var change in pendingChanges)
                        {
                            nScript.Replace(change.Item1, change.Item2);
                        }
                    }, "Fix explicitly implemented members");
                }

                script.Replace(typeDeclaration, newTypeDeclaration);
            }