コード例 #1
0
        MemberReferenceCollection GetReferences(RefactoringOptions options)
        {
            CodeRefactorer   refactorer = IdeApp.Workspace.GetCodeRefactorer(IdeApp.ProjectOperations.CurrentSelectedSolution);
            IProgressMonitor monitor    = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor(this.Name, null);

            if (options.SelectedItem is IType)
            {
                IType cls = (IType)options.SelectedItem;
                return(refactorer.FindClassReferences(monitor, cls, RefactoryScope.Solution, true));
            }
            else if (options.SelectedItem is LocalVariable)
            {
                return(refactorer.FindVariableReferences(monitor, (LocalVariable)options.SelectedItem));
            }
            else if (options.SelectedItem is IParameter)
            {
                return(refactorer.FindParameterReferences(monitor, (IParameter)options.SelectedItem, true));
            }
            else if (options.SelectedItem is IMember)
            {
                IMember member = (IMember)options.SelectedItem;
                Dictionary <string, HashSet <DomLocation> > foundLocations = new Dictionary <string, HashSet <DomLocation> > ();
                MemberReferenceCollection result = new MemberReferenceCollection();
                foreach (IMember m in CollectMembers(member.DeclaringType.SourceProjectDom, member))
                {
                    foreach (MemberReference r in refactorer.FindMemberReferences(monitor, m.DeclaringType, m, true))
                    {
                        DomLocation location = new DomLocation(r.Line, r.Column);
                        if (!foundLocations.ContainsKey(r.FileName))
                        {
                            foundLocations[r.FileName] = new HashSet <DomLocation> ();
                        }
                        if (foundLocations[r.FileName].Contains(location))
                        {
                            continue;
                        }
                        foundLocations[r.FileName].Add(location);
                        result.Add(r);
                    }
                }
                return(result);
            }
            return(null);
        }