/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.List <string> GetMethodNames()
        {
            System.Collections.Generic.List <string> M = new List <string>();

            EnvDTE80.FileCodeModel2 FileCodeModel = this.Application.ActiveDocument.ProjectItem.FileCodeModel as EnvDTE80.FileCodeModel2;
            EnvDTE.CodeElements     elements      = FileCodeModel.CodeElements;

            foreach (EnvDTE.CodeElement element in elements)
            {
                if (element.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
                {
                    foreach (EnvDTE.CodeElement element2 in element.Children)
                    {
                        if (element2.Kind == EnvDTE.vsCMElement.vsCMElementClass)
                        {
                            EnvDTE80.CodeClass2 CurrentClass = element2 as EnvDTE80.CodeClass2;

                            foreach (EnvDTE.CodeElement element3 in element2.Children)
                            {
                                if (element3.Kind == EnvDTE.vsCMElement.vsCMElementFunction)
                                {
                                    EnvDTE80.CodeFunction2 CurrentFunction = element3 as EnvDTE80.CodeFunction2;
                                    M.Add(CurrentFunction.Name);
                                }
                            }
                        }
                    }
                }
            }
            return(M);
        }
示例#2
0
 private EnvDTE.CodeClass FirstClass(EnvDTE.CodeElements elements)
 {
     foreach (EnvDTE.CodeElement c in elements)
     {
         if (c is EnvDTE.CodeClass)
         {
             return(c as EnvDTE.CodeClass);
         }
     }
     return(null);
 }
示例#3
0
 private EnvDTE.CodeNamespace FirstNamespace(EnvDTE.CodeElements elements)
 {
     foreach (EnvDTE.CodeElement c in elements)
     {
         if (c is EnvDTE.CodeNamespace)
         {
             return(c as EnvDTE.CodeNamespace);
         }
     }
     return(null);
 }
 private void AddInterfaces(List <CodeInterface> interfaces, EnvDTE.CodeElements codeElements)
 {
     foreach (CodeElement codeElement in codeElements)
     {
         if (codeElement.Kind == EnvDTE.vsCMElement.vsCMElementInterface)
         {
             interfaces.Add((CodeInterface)codeElement);
         }
         if (codeElement.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
         {
             AddInterfaces(interfaces, ((EnvDTE.CodeNamespace)codeElement).Members);
         }
     }
 }
示例#5
0
        private List <ICodeElementModel> MapCodeElements(EnvDTE.CodeElements codeElements)
        {
            var result = new List <ICodeElementModel>();

            if (codeElements == null)
            {
                return(result);
            }

            for (int i = 1; i < codeElements.Count; i++)
            {
                result.Add(new CodeElementModel(codeElements.Item(i)));
            }
            return(result);
        }
示例#6
0
        /*public void GetCodeElementAtCursor()
         * {
         *      EnvDTE.CodeElement objCodeElement = default(EnvDTE.CodeElement);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objCursorTextPoint = GetCursorTextPoint();
         *
         *              if ((objCursorTextPoint != null))
         *              {
         *                      // Get the class at the cursor
         *                      objCodeElement = GetCodeElementAtTextPoint(vsCMElement.vsCMElementClass, DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements, objCursorTextPoint);
         *              }
         *
         *              if (objCodeElement == null)
         *              {
         *                      MessageBox.Show("No class found at the cursor!");
         *              }
         *              else
         *              {
         *                      MessageBox.Show("Class at the cursor: " + objCodeElement.FullName);
         *              }
         *      }
         *      catch (System.Exception ex)
         *      {
         *              MessageBox.Show(ex.ToString);
         *      }
         * }*/

        /*private EnvDTE.TextPoint GetCursorTextPoint()
         * {
         *      EnvDTE.TextDocument objTextDocument = default(EnvDTE.TextDocument);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objTextDocument = (EnvDTE.TextDocument)DTE.ActiveDocument.Object;
         *              objCursorTextPoint = objTextDocument.Selection.ActivePoint();
         *      }
         *      catch (System.Exception ex)
         *      {
         *      }
         *
         *      return objCursorTextPoint;
         * }*/

        public static EnvDTE.CodeElement GetCodeElementAtTextPoint(EnvDTE.vsCMElement eRequestedCodeElementKind, EnvDTE.CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint)
        {
            EnvDTE.CodeElement  objResultCodeElement  = default(EnvDTE.CodeElement);
            EnvDTE.CodeElements colCodeElementMembers = default(EnvDTE.CodeElements);
            EnvDTE.CodeElement  objMemberCodeElement  = default(EnvDTE.CodeElement);

            if ((colCodeElements != null))
            {
                foreach (CodeElement objCodeElement in colCodeElements)
                {
                    /*if (objCodeElement.StartPoint.GreaterThan(objTextPoint))
                     * {
                     *      // The code element starts beyond the point
                     * }
                     * else if (objCodeElement.EndPoint.LessThan(objTextPoint))
                     * {
                     *      // The code element ends before the point
                     *
                     *      // The code element contains the point
                     * }
                     * else*/
                    {
                        if (objCodeElement.Kind == eRequestedCodeElementKind)
                        {
                            // Found
                            objResultCodeElement = objCodeElement;
                        }

                        // We enter in recursion, just in case there is an inner code element that also
                        // satisfies the conditions, for example, if we are searching a namespace or a class
                        colCodeElementMembers = GetCodeElementMembers(objCodeElement);

                        objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint);

                        if ((objMemberCodeElement != null))
                        {
                            // A nested code element also satisfies the conditions
                            objResultCodeElement = objMemberCodeElement;
                        }

                        break;                         // TODO: might not be correct. Was : Exit For
                    }
                }
            }

            return(objResultCodeElement);
        }
示例#7
0
        private static EnvDTE.CodeElements GetCodeElementMembers(CodeElement objCodeElement)
        {
            EnvDTE.CodeElements colCodeElements = default(EnvDTE.CodeElements);

            if (objCodeElement is EnvDTE.CodeNamespace)
            {
                colCodeElements = ((EnvDTE.CodeNamespace)objCodeElement).Members;
            }
            else if (objCodeElement is EnvDTE.CodeType)
            {
                colCodeElements = ((EnvDTE.CodeType)objCodeElement).Members;
            }
            else if (objCodeElement is EnvDTE.CodeFunction)
            {
                colCodeElements = ((EnvDTE.CodeFunction)objCodeElement).Parameters;
            }
            return(colCodeElements);
        }
示例#8
0
 public static void WalkCodeElements(EnvDTE.CodeElements codeElements, string indent)
 {
     foreach (EnvDTE.CodeElement codeElem in codeElements)
     {
         if (codeElem.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
         {
             if (codeElem.Name != "System")                                      // walking System/Microsoft namespaces generates too much output
             {
                 if (codeElem.Name != "Microsoft")
                 {
                     WalkNamespace((EnvDTE.CodeNamespace)codeElem, indent);
                 }
             }
         }
         else
         {
             doCodeElement(codeElem, indent);
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string GetCurrentClassName()
        {
            EnvDTE80.FileCodeModel2 FileCodeModel = this.Application.ActiveDocument.ProjectItem.FileCodeModel as EnvDTE80.FileCodeModel2;
            EnvDTE.CodeElements     elements      = FileCodeModel.CodeElements;

            foreach (EnvDTE.CodeElement element in elements)
            {
                if (element.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
                {
                    foreach (EnvDTE.CodeElement element2 in element.Children)
                    {
                        if (element2.Kind == EnvDTE.vsCMElement.vsCMElementClass)
                        {
                            EnvDTE80.CodeClass2 CurrentClass = element2 as EnvDTE80.CodeClass2;
                            return(CurrentClass.Name);
                        }
                    }
                }
            }
            return(null);
        }
示例#10
0
        /// <summary>
        /// Documents child CodeElements within a document.
        /// </summary>
        /// <param name="document">The TextDocument that contains the code.</param>
        /// <param name="elements">The elements to document.</param>
        private void DocumentElements(EnvDTE.TextDocument document, EnvDTE.CodeElements elements)
        {
            try
            {
                foreach (CodeElement element in elements)
                {
                    switch (element.Kind)
                    {
                    case vsCMElement.vsCMElementFunction:
                        EnvDTE.CodeFunction func;
                        func = (EnvDTE.CodeFunction)element;
                        if (func.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, func.Children);
                        break;

                    case vsCMElement.vsCMElementProperty:
                        EnvDTE.CodeProperty prop;
                        prop = (EnvDTE.CodeProperty)element;
                        if (prop.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, prop.Children);
                        break;

                    case vsCMElement.vsCMElementEvent:
                        EnvDTE80.CodeEvent evt;
                        evt = (EnvDTE80.CodeEvent)element;
                        if (evt.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, evt.Children);
                        break;

                    case vsCMElement.vsCMElementClass:
                        EnvDTE.CodeClass cls;
                        cls = (EnvDTE.CodeClass)element;
                        if (cls.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, cls.Children);
                        break;

                    case vsCMElement.vsCMElementStruct:
                        EnvDTE.CodeStruct strct;
                        strct = (EnvDTE.CodeStruct)element;
                        if (strct.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, strct.Children);
                        break;

                    case vsCMElement.vsCMElementDelegate:
                        EnvDTE.CodeDelegate dlg;
                        dlg = (EnvDTE.CodeDelegate)element;
                        if (dlg.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, dlg.Children);
                        break;

                    case vsCMElement.vsCMElementEnum:
                        EnvDTE.CodeEnum enm;
                        enm = (EnvDTE.CodeEnum)element;
                        if (enm.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, enm.Children);
                        break;

                    case vsCMElement.vsCMElementVariable:
                        EnvDTE.CodeVariable var;

                        var = (EnvDTE.CodeVariable)element;
                        if (var.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        break;

                    case vsCMElement.vsCMElementNamespace:
                        EnvDTE.CodeNamespace nmspc;
                        nmspc = (EnvDTE.CodeNamespace)element;
                        DocumentElements(document, nmspc.Children);
                        break;

                    case vsCMElement.vsCMElementInterface:
                        EnvDTE.CodeInterface inter;
                        inter = (EnvDTE.CodeInterface)element;
                        if (inter.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, inter.Children);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }