private void LoadTypes(Dictionary <string, Type> availableTypes, ICollection types, Project dteProject)
            {
                bool   isWebProject        = DteHelper2.IsWebProject(dteProject);
                string projectAssemblyName = GetAssemblyName(dteProject);

                foreach (Type type in types)
                {
                    // Filtering of non-public types must be done with a type filter provider.
                    // By default, if none is specified, the PublicTypeFilter will do just that.
                    if (!availableTypes.ContainsKey(type.FullName))
                    {
                        if (!isWebProject &&
                            !type.Assembly.FullName.StartsWith(projectAssemblyName, StringComparison.OrdinalIgnoreCase))
                        {
                            availableTypes.Add(type.FullName, type);
                        }
                        else
                        {
                            availableTypes.Add(type.FullName, new ProjectType(type));
                        }
                    }
                }
            }
 public RunCodeAnalysisRulesCommand(IServiceProvider provider)
     : base(provider)
 {
     this.project = VsHelper.ToDteProject(DteHelper2.GetCurrentSelection(provider));
 }
示例#3
0
        public static bool AddProjectItemDialog(
            IServiceProvider provider,
            string title,
            string templateName, bool addExisting = false)
        {
            Guard.ArgumentNotNull(provider, "provider");
            Guard.ArgumentNotNullOrEmptyString(title, "title");
            Guard.ArgumentNotNullOrEmptyString(templateName, "templateName");

            try
            {
                IVsSolution solution = provider.GetService(typeof(IVsSolution)) as IVsSolution;
                uint        pitemid  = 0;
                using (HierarchyNode hierarchy = new HierarchyNode(solution, DteHelper2.GetCurrentSelection(provider, out pitemid)))
                    using (HierarchyNode child = new HierarchyNode(hierarchy, pitemid))
                    {
                        Guid       rguidProject = hierarchy.TypeGuid;
                        IVsProject project      = child.IsSolution ? null : (IVsProject)child.Hierarchy;

                        string strFilter    = String.Empty;
                        string templatePath = GetTemplatePathFromProject(hierarchy);
                        int    iDontShowAgain;

                        IVsAddProjectItemDlg2 addProjectItemDlg2 = (IVsAddProjectItemDlg2)provider.GetService(typeof(SVsAddProjectItemDlg));

                        uint uiFlags;
                        if (addExisting)
                        {
                            uiFlags = (uint)(__VSADDITEMFLAGS.VSADDITEM_AddExistingItems |
                                             __VSADDITEMFLAGS.VSADDITEM_ProjectHandlesLinks |
                                             __VSADDITEMFLAGS.VSADDITEM_AllowStickyFilter |
                                             __VSADDITEMFLAGS.VSADDITEM_ShowLocationField);
                            //strFilter = "Data Contract (*.datacontract)";
                        }
                        else
                        {
                            uiFlags = (uint)(__VSADDITEMFLAGS.VSADDITEM_AddNewItems |
                                             __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName |
                                             __VSADDITEMFLAGS.VSADDITEM_AllowHiddenTreeView |
                                             __VSADDITEMFLAGS.VSADDITEM_AllowStickyFilter |
                                             __VSADDITEMFLAGS.VSADDITEM_ShowLocationField);
                        }

                        ErrorHandler.ThrowOnFailure(
                            addProjectItemDlg2.AddProjectItemDlgTitled(
                                child.IsRoot ? VSConstants.VSITEMID_ROOT : pitemid,
                                ref rguidProject,
                                project,
                                uiFlags,
                                string.Format(CultureInfo.CurrentCulture, title, hierarchy.Name),
                                templatePath,
                                templateName,
                                ref strLocation,
                                ref strFilter,
                                out iDontShowAgain),
                            VSConstants.OLE_E_PROMPTSAVECANCELLED);
                        return(true);
                    }
            }
            catch (Exception error)
            {
                Logger.Write(error);
            }
            return(false);
        }
示例#4
0
 public static bool IsCSharpOrVbProject(IServiceProvider serviceProvider, bool excludeWebProjects)
 {
     EnvDTE.DTE dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
     return(IsCSharpOrVbProject(DteHelper2.GetSelectedProject(dte), excludeWebProjects));
 }