コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CustomTypeProvider"/> class.
        /// </summary>
        /// <param name="provider">The provider.</param>
        public CustomTypeProvider(IServiceProvider provider, List <Project> additionalProjects, bool useProjectItemWrapper)
        {
            this.useProjectItemWrapper = useProjectItemWrapper;
            DynamicTypeService typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            availableTypes = new Dictionary <string, Type>();

            if (additionalProjects != null && additionalProjects.Count > 0)
            {
                foreach (Project project in additionalProjects)
                {
                    IVsHierarchy          additionalHierarchy = DteHelper.GetVsHierarchy(provider, project);
                    ITypeDiscoveryService additionalDiscovery = typeService.GetTypeDiscoveryService(additionalHierarchy);
                    AddTypes(additionalDiscovery, project);
                }
            }
            else
            {
                IVsHierarchy hier = DteHelper.GetCurrentSelection(provider);
                Debug.Assert(hier != null, "No active hierarchy is selected.");

                ITypeDiscoveryService discovery = typeService.GetTypeDiscoveryService(hier);
                Project dteProject = VSHelper.ToDteProject(hier);

                AddTypes(discovery, dteProject);
            }

            if (availableTypes.Count > 0 && TypesChanged != null)
            {
                TypesChanged(this, new EventArgs());
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            DynamicTypeService typeService = (DynamicTypeService)context.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            IVsHierarchy hier = DteHelper.GetCurrentSelection(context);

            Debug.Assert(hier != null, "No active hierarchy is selected.");

            ITypeDiscoveryService typeDiscovery = typeService.GetTypeDiscoveryService(hier);

            if (typeDiscovery != null)
            {
                List <string> types = new List <string>();
                foreach (Type type in typeDiscovery.GetTypes(typeof(object), false))
                {
                    if (ShouldInclude(type))
                    {
                        types.Add(type.FullName);
                    }
                }

                types.Sort(StringComparer.CurrentCulture);

                return(new StandardValuesCollection(types));
            }
            else
            {
                return(new StandardValuesCollection(new List <string>()));
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns the discovered types for autocomplete
        /// </summary>
        protected virtual IEnumerable <Type> DiscoverTypes()
        {
            DynamicTypeService    typeService          = (DynamicTypeService)DataGridView.Site.GetService(typeof(DynamicTypeService));
            IVsHierarchy          hier                 = DteHelper.GetCurrentSelection(DataGridView.Site);
            ITypeDiscoveryService typeDiscoveryService = typeService.GetTypeDiscoveryService(hier);

            return((IEnumerable <Type>)typeDiscoveryService.GetTypes(typeof(object), false));
        }
コード例 #4
0
 protected override void OnExec()
 {
     if (template.IsVisibleFromContextMenu)
     {
         IConfigurationService configService =
             (IConfigurationService)ServiceProvider.GetService(typeof(IConfigurationService), true);
         if (template.Kind == TemplateKind.Project)
         {
             IVsSolution3             solution = (IVsSolution3)ServiceProvider.GetService(typeof(SVsSolution), true);
             IVsBrowseProjectLocation browseProjectLocation = null;
             uint cnpvdeFlags = (uint)(__VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_ALWAYSADDTOSOLUTION | __VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_ADDNESTEDTOSELECTION);
             //browseProjectLocation = this;
             //cnpvdeFlags |= (uint)(__VSCREATENEWPROJVIADLGEXFLAGS.VNPVDE_OVERRIDEBROWSEBUTTON);
             solution.CreateNewProjectViaDlgEx(Microsoft.Practices.RecipeFramework.VisualStudio.Properties.Resources.IDD_ADDPROJECTDLG,
                                               null,
                                               configService.CurrentPackage.Caption,
                                               this.template.Name,
                                               null,
                                               cnpvdeFlags,
                                               browseProjectLocation);
         }
         else if (template.Kind == TemplateKind.ProjectItem)
         {
             uint                  itemid            = 0;
             IVsProject            vsProject         = DteHelper.GetCurrentSelection(this.ServiceProvider, out itemid) as IVsProject;
             IVsAddProjectItemDlg2 addProjectItemDlg =
                 (IVsAddProjectItemDlg2)ServiceProvider.GetService(typeof(SVsAddProjectItemDlg), true);
             __VSADDITEMFLAGS addItemsFlags = __VSADDITEMFLAGS.VSADDITEM_AddNewItems | __VSADDITEMFLAGS.VSADDITEM_SuggestTemplateName;
             Guid             projectGuid   = this.template.ProjectFactory;
             string           location      = String.Empty;
             string           filter        = String.Empty;
             int dontShowAgain = VSConstantsEx.TRUE;
             addProjectItemDlg.AddProjectItemDlgTitled(itemid,
                                                       ref projectGuid,
                                                       vsProject,
                                                       (uint)addItemsFlags,
                                                       null,
                                                       configService.CurrentPackage.Caption,
                                                       this.template.Name,
                                                       ref location,
                                                       ref filter,
                                                       out dontShowAgain);
         }
     }
 }
コード例 #5
0
        private void ValidateTypeName(string typeName)
        {
            DynamicTypeService typeService = (DynamicTypeService)site.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            IVsHierarchy hier = DteHelper.GetCurrentSelection(site);

            Debug.Assert(hier != null, "No active hierarchy is selected.");

            ITypeResolutionService resolution = typeService.GetTypeResolutionService(hier);
            Type type = resolution.GetType(TypeHelper.ParseGenericType(typeName));

            if (type == null)
            {
                throw new TypeLoadException(string.Format(CultureInfo.CurrentUICulture, Resources.TypeNameValidatorTypeNotFound, typeName));
            }
        }
コード例 #6
0
        /// <summary>
        /// Converts the specified value object to a <see cref="T:System.String"></see> object.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> to use.</param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object"></see> that represents the converted value.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">The conversion could not be performed. </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value is string)
            {
                DynamicTypeService typeService = (DynamicTypeService)context.GetService(typeof(DynamicTypeService));
                Debug.Assert(typeService != null, "No dynamic type service registered.");

                IVsHierarchy hier = DteHelper.GetCurrentSelection(context);
                Debug.Assert(hier != null, "No active hierarchy is selected.");

                ITypeResolutionService resolution = typeService.GetTypeResolutionService(hier);
                Type type = resolution.GetType(value.ToString());
                return(type);
            }
            else
            {
                return(base.ConvertFrom(context, culture, value));
            }
        }
コード例 #7
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"></see> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"></see> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            DynamicTypeService typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService));

            IVsHierarchy hier = DteHelper.GetCurrentSelection(provider);

            ITypeDiscoveryService typeDiscovery = typeService.GetTypeDiscoveryService(hier);

            Project project = ToDteProject(hier);

            if (DteHelper.IsWebProject(project))
            {
                VSWebSite     vsProject  = (VSWebSite)project.Object;
                List <string> assemblies = new List <string>();
                foreach (AssemblyReference reference in vsProject.References)
                {
                    if (!string.IsNullOrEmpty(reference.FullPath))
                    {
                        assemblies.Add(reference.FullPath);
                    }
                }

                MethodInfo setAsssembliesMethod = typeDiscovery.GetType().GetMethod(SetAssembliesMethodName,
                                                                                    BindingFlags.NonPublic | BindingFlags.Instance);
                setAsssembliesMethod.Invoke(typeDiscovery, new object[] { assemblies.ToArray() });
            }

            if (typeDiscovery != null)
            {
                List <string>   assembliesAdded = new List <string>();
                List <Assembly> assemblies      = new List <Assembly>();
                List <Type>     types           = new List <Type>();

                foreach (Type type in typeDiscovery.GetTypes(typeof(object), false))
                {
                    if (ShouldInclude(type))
                    {
                        if (!assembliesAdded.Contains(type.Assembly.FullName))
                        {
                            assembliesAdded.Add(type.Assembly.FullName);
                            assemblies.Add(type.Assembly);
                        }
                        types.Add(type);
                    }
                }

                IWindowsFormsEditorService svc  = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                ClassBrowserEditorForm     form = new ClassBrowserEditorForm(assemblies, types);
                DialogResult result;

                if (svc != null)
                {
                    result = svc.ShowDialog(form);
                }
                else
                {
                    result = form.ShowDialog();
                }

                if (result == DialogResult.OK)
                {
                    return(form.TypeFullName);
                }
                else
                {
                    return(value);
                }
            }
            else
            {
                return(null);
            }
        }