예제 #1
0
        /// <summary>
        /// Recursive enumeration of all solution items.
        /// </summary>
        private static bool InternalEnumeration(ProjectItem item, IList <CodeNamespace> codeNamespaces,
                                                IList <CodeClass> codeClasses, IList <CodeStruct> codeStructs,
                                                IList <CodeFunction> codeFunctions,
                                                IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder)
        {
            IList <CodeNamespace> interNamespaces;
            IList <CodeClass>     interClasses;
            IList <CodeStruct>    interStructs;
            IList <CodeFunction>  internalFunctions;
            CodeElements          elements;

            // enumerate through all namespaces:
            if (codeNamespaces != null)
            {
                foreach (CodeNamespace n in codeNamespaces)
                {
                    elements        = n.Members;
                    interNamespaces = EditorHelper.GetList <CodeNamespace>(elements, vsCMElement.vsCMElementNamespace);

                    interClasses = classFinder != null?EditorHelper.GetList <CodeClass>(elements, vsCMElement.vsCMElementClass) : null;

                    interStructs = structFinder != null?EditorHelper.GetList <CodeStruct>(elements, vsCMElement.vsCMElementStruct) : null;

                    internalFunctions = EditorHelper.GetList <CodeFunction>(elements, vsCMElement.vsCMElementFunction);

                    if (InternalEnumeration(item, interNamespaces, interClasses, interStructs, internalFunctions, classFinder, structFinder, functionFinder))
                    {
                        return(true);
                    }
                }
            }

            // enumerate classes:
            if (codeClasses != null && classFinder != null)
            {
                foreach (CodeClass c in codeClasses)
                {
                    if (classFinder.MatchCriteria(c))
                    {
                        Window        w   = item.Open(Constants.vsViewKindTextView);
                        TextSelection sel = w.Selection as TextSelection;

                        classFinder.Activate(item, c, w, sel);
                        return(true);
                    }

                    interClasses = EditorHelper.GetList <CodeClass>(c.Members, vsCMElement.vsCMElementClass);

                    if (codeStructs != null)
                    {
                        interStructs = EditorHelper.GetList <CodeStruct>(c.Members, vsCMElement.vsCMElementStruct);
                    }
                    else
                    {
                        interStructs = null;
                    }

                    if (InternalEnumeration(item, null, interClasses, interStructs, null, classFinder, structFinder, null))
                    {
                        return(true);
                    }
                }
            }

            // enumerate structures:
            if (codeStructs != null && structFinder != null)
            {
                foreach (CodeStruct s in codeStructs)
                {
                    if (structFinder.MatchCriteria(s))
                    {
                        Window        w   = item.Open(Constants.vsViewKindTextView);
                        TextSelection sel = w.Selection as TextSelection;

                        structFinder.Activate(item, s, w, sel);
                        return(true);
                    }

                    if (classFinder != null)
                    {
                        interClasses = EditorHelper.GetList <CodeClass>(s.Members, vsCMElement.vsCMElementClass);
                    }
                    else
                    {
                        interClasses = null;
                    }
                    interStructs = EditorHelper.GetList <CodeStruct>(s.Members, vsCMElement.vsCMElementStruct);

                    if (InternalEnumeration(item, null, interClasses, interStructs, null, classFinder, structFinder, null))
                    {
                        return(true);
                    }
                }
            }

            // enumerate all global functions:
            if (codeFunctions != null && functionFinder != null)
            {
                foreach (CodeFunction f in codeFunctions)
                {
                    if (functionFinder.MatchCriteria(f))
                    {
                        Window        w   = item.Open(Constants.vsViewKindTextView);
                        TextSelection sel = w.Selection as TextSelection;

                        functionFinder.Activate(item, f, w, sel);
                        return(true);
                    }
                }
            }

            return(false);
        }