コード例 #1
0
        /// <summary>
        /// loads all classes in solution
        /// </summary>
        /// <param name="projects">All projects in the solution</param>
        /// <param name="editor">The textbox to display progress</param>
        /// <param name="withProperties">True if you only want classes with properties only.  False if you want classes with Functions</param>
        /// <returns></returns>
        public static List <CodeClass> ClassSearch(EnvDTE.Projects projects, FastColoredTextBox editor)
        {
            var projs        = CodeDiscoverer.Projects();
            var foundClasses = new List <CodeClass>();

            editor.Text = "Loading projects\r\n";

            foreach (var proj in projs)
            {
                if (proj == null)
                {
                    continue;
                }
                editor.AppendText("\r\n" + proj.Name);

                if (proj.ProjectItems == null || proj.CodeModel == null)
                {
                    continue;
                }
                // var timer = new Stopwatch();
                // timer.Start();
                var projectItems = GetProjectItems(proj.ProjectItems).Where(v => v.Name.Contains(".cs"));

                // foundClasses.AddRange(projectItems.Where(c => c.FileCodeModel != null).SelectMany(x => x.FileCodeModel.CodeElements.OfType<CodeNamespace>().SelectMany(xx => xx.Members.OfType<CodeClass>())));

                Parallel.ForEach(projectItems, (c) =>
                {
                    if (c == null || c.FileCodeModel == null)
                    {
                        return;
                    }

                    //foundClasses.AddRange(c.FileCodeModel.CodeElements.OfType<CodeNamespace>().SelectMany(x => x.Members.OfType<CodeClass>()));

                    foreach (var ns in c.FileCodeModel.CodeElements.OfType <CodeNamespace>())
                    {
                        foreach (var member in ns.Members.OfType <CodeClass>())
                        {
                            if (member == null || member.Kind != vsCMElement.vsCMElementClass)
                            {
                                continue;
                            }
                            foundClasses.Add(member);
                        }
                    }
                });

                //timer.Stop();

                // editor.AppendText("\r\n" + proj.Name + "- " + timer.ElapsedMilliseconds + "ms");
            }

            if (foundClasses == null || foundClasses.Count == 0)
            {
                throw new Exception("Could not find any classes");
            }
            foundClasses.Sort((x, y) => x.FullName.CompareTo(y.FullName));
            return(foundClasses);
        }
コード例 #2
0
        public string IterateMembers(CodeType selectedClass, int depth)
        {
            depth++;
            var str = "";

            foreach (CodeProperty member in selectedClass.Members.OfType <CodeProperty>())
            {
                try
                {
                    if (CodeDiscoverer.IsValidPublicProperty((CodeElement)member) == false)
                    {
                        continue;
                    }

                    str += GetParam(member.Type, member.Name, depth);
                }
                catch (Exception ex)
                {
                    //ignore silently
                }
            }


            foreach (CodeClass inheritedClass in selectedClass.Bases.OfType <CodeClass>())
            {
                try
                {
                    foreach (CodeProperty member in inheritedClass.Members.OfType <CodeProperty>())
                    {
                        try
                        {
                            var name = member.Name;

                            if (CodeDiscoverer.IsValidPublicProperty((CodeElement)member) == false)
                            {
                                continue;
                            }

                            str += GetParam(member.Type, member.Name, depth);
                        }
                        catch (Exception ex)
                        {
                            //ignore silently
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ignore silently
                }
            }



            str = str.ReplaceLastOccurrence(",", "");
            return(str);
        }
コード例 #3
0
        public CodeTypeRef CheckForTypeInAllProjects(string typeNameAsInCode)
        {
            //lol check in all projects
            foreach (Project projFolders in CodeDiscoverer.Projects())
            {
                try
                {
                    var codeType = projFolders.CodeModel.CodeTypeFromFullName(typeNameAsInCode);

                    if (codeType != null)
                    {
                        return(projFolders.CodeModel.CreateCodeTypeRef(codeType));
                    }
                }
                catch { }
            }
            return(null);
        }