Exemple #1
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>()));
            }
        }
    void InitDict(ITypeDescriptorContext context)
    {
        //sometimes happens...
        if (context == null)
        {
            return;
        }
        Dictionary <string, MyReferencableObject> tvalues = new Dictionary <string, MyReferencableObject>();

        tvalues.Add(empty, null);
        ITypeDiscoveryService Service = (ITypeDiscoveryService)context.GetService(typeof(ITypeDiscoveryService));

        //sometimes happens...
        if (Service == null)
        {
            return;
        }
        foreach (Type declaration in Service.GetTypes(ContainerType, false))
        {
            foreach (FieldInfo fieldInfo in declaration.GetFields())
            {
                if (context.PropertyDescriptor.PropertyType.IsAssignableFrom(fieldInfo.FieldType))
                {
                    MyReferencableObject var = (MyReferencableObject)fieldInfo.GetValue(null);
                    var.FieldInfo = fieldInfo;
                    tvalues.Add(var.FullName, var);
                }
            }
        }
        //in a perfect world the if should not be necessary....
        if (tvalues.Count > 1 || values == null)
        {
            values = tvalues;
        }
    }
        void initValues(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return;
            }

            var tvalues = new Dictionary <string, RGBEncoding>();

            tvalues.Add("(none)", null);

            ITypeDiscoveryService Service = (ITypeDiscoveryService)context.GetService(typeof(ITypeDiscoveryService));

            if (Service == null)
            {
                return;
            }

            foreach (RGBEncoding enc in RGBEncoding.list)
            {
                tvalues.Add(enc.Name, enc);
            }
            if (tvalues.Count > 1 || values == null)
            {
                values = tvalues;
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets the mask property value fromt the MaskDesignerDialog.
        /// The IUIService is used to show the mask designer dialog within VS so it doesn't get blocked if focus
        /// is moved to anoter app.
        /// </summary>
        internal static string EditMask(ITypeDiscoveryService discoverySvc, IUIService uiSvc, MaskedTextBox instance, IHelpService helpService)
        {
            Debug.Assert(instance != null, "Null masked text box.");
            string mask = null;

            // Launching modal dialog in System aware mode.
            MaskDesignerDialog dlg = DpiHelper.CreateInstanceInSystemAwareContext(() => new MaskDesignerDialog(instance, helpService));

            try
            {
                dlg.DiscoverMaskDescriptors(discoverySvc);  // fine if service is null.

                // Show dialog from VS.
                DialogResult dlgResult = uiSvc != null?uiSvc.ShowDialog(dlg) : dlg.ShowDialog();

                if (dlgResult == DialogResult.OK)
                {
                    mask = dlg.Mask;

                    // ValidatingType is not browsable so we don't need to set the property through the designer.
                    if (dlg.ValidatingType != instance.ValidatingType)
                    {
                        instance.ValidatingType = dlg.ValidatingType;
                    }
                }
            }
            finally
            {
                dlg.Dispose();
            }

            // Will return null if dlgResult != OK.
            return(mask);
        }
        private void PopulateColumnTypesCombo()
        {
            this.columnTypesCombo.Items.Clear();
            IDesignerHost host = (IDesignerHost)this.liveDataGridView.Site.GetService(iDesignerHostType);

            if (host != null)
            {
                ITypeDiscoveryService service = (ITypeDiscoveryService)host.GetService(iTypeDiscoveryServiceType);
                if (service != null)
                {
                    foreach (System.Type type in DesignerUtils.FilterGenericTypes(service.GetTypes(dataGridViewColumnType, false)))
                    {
                        if (((type != dataGridViewColumnType) && !type.IsAbstract) && (type.IsPublic || type.IsNestedPublic))
                        {
                            DataGridViewColumnDesignTimeVisibleAttribute attribute = TypeDescriptor.GetAttributes(type)[dataGridViewColumnDesignTimeVisibleAttributeType] as DataGridViewColumnDesignTimeVisibleAttribute;
                            if ((attribute == null) || attribute.Visible)
                            {
                                this.columnTypesCombo.Items.Add(new ComboBoxItem(type));
                            }
                        }
                    }
                    this.columnTypesCombo.SelectedIndex = this.TypeToSelectedIndex(typeof(DataGridViewTextBoxColumn));
                }
            }
        }
Exemple #6
0
        public static IValidationCollectorReflector Create(ITypeDiscoveryService typeDiscoveryService, IValidatedTypeResolver validatedTypeResolver)
        {
            ArgumentUtility.CheckNotNull("typeDiscoveryService", typeDiscoveryService);
            ArgumentUtility.CheckNotNull("validatedTypeResolver", validatedTypeResolver);

            return(new DiscoveryServiceBasedValidationCollectorReflector(typeDiscoveryService, validatedTypeResolver));
        }
Exemple #7
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());
            }
        }
Exemple #8
0
        public MappingReflector(
            ITypeDiscoveryService typeDiscoveryService,
            IClassIDProvider classIDProvider,
            IMemberInformationNameResolver nameResolver,
            IPropertyMetadataProvider propertyMetadataProvider,
            IDomainModelConstraintProvider domainModelConstraintProvider,
            IDomainObjectCreator domainObjectCreator)
        {
            ArgumentUtility.CheckNotNull("typeDiscoveryService", typeDiscoveryService);
            ArgumentUtility.CheckNotNull("classIDProvider", classIDProvider);
            ArgumentUtility.CheckNotNull("propertyMetadataProvider", propertyMetadataProvider);
            ArgumentUtility.CheckNotNull("domainModelConstraintProvider", domainModelConstraintProvider);
            ArgumentUtility.CheckNotNull("nameResolver", nameResolver);
            ArgumentUtility.CheckNotNull("domainObjectCreator", domainObjectCreator);

            _typeDiscoveryService          = typeDiscoveryService;
            _classIDProvider               = classIDProvider;
            _propertyMetadataProvider      = propertyMetadataProvider;
            _domainModelConstraintProvider = domainModelConstraintProvider;
            _nameResolver         = nameResolver;
            _mappingObjectFactory = new ReflectionBasedMappingObjectFactory(
                _nameResolver,
                _classIDProvider,
                _propertyMetadataProvider,
                _domainModelConstraintProvider,
                domainObjectCreator);
        }
        internal static IDictionary <Type, DataControlFieldDesigner> GetCustomFieldDesigners(DesignerForm designerForm, DataBoundControl control)
        {
            Dictionary <Type, DataControlFieldDesigner> dictionary = new Dictionary <Type, DataControlFieldDesigner>();
            ITypeDiscoveryService service = (ITypeDiscoveryService)control.Site.GetService(typeof(ITypeDiscoveryService));

            if (service != null)
            {
                foreach (Type type in service.GetTypes(typeof(DataControlField), false))
                {
                    DesignerAttribute customAttribute = (DesignerAttribute)Attribute.GetCustomAttribute(type, typeof(DesignerAttribute));
                    if (customAttribute != null)
                    {
                        Type type2 = Type.GetType(customAttribute.DesignerTypeName, false, true);
                        if ((type2 != null) && type2.IsSubclassOf(typeof(DataControlFieldDesigner)))
                        {
                            try
                            {
                                DataControlFieldDesigner designer = (DataControlFieldDesigner)Activator.CreateInstance(type2);
                                if (designer.IsEnabled(control))
                                {
                                    designer.DesignerForm = designerForm;
                                    dictionary.Add(type, designer);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            return(dictionary);
        }
        /// <summary>
        /// Uses the specified ITypeDiscoveryService service provider to discover MaskDescriptor objects from
        /// the referenced assemblies.
        /// </summary>
        public void DiscoverMaskDescriptors(ITypeDiscoveryService discoveryService)
        {
            if (discoveryService is null)
            {
                return;
            }

            ICollection descriptors = DesignerUtils.FilterGenericTypes(discoveryService.GetTypes(typeof(MaskDescriptor), false /* excludeGlobalTypes */));

            // Note: This code assumes DesignerUtils.FilterGenericTypes return a valid ICollection (collection of MaskDescriptor types).
            foreach (Type t in descriptors)
            {
                if (t.IsAbstract || !t.IsPublic)
                {
                    continue;
                }

                // Since mask descriptors can be provided from external sources, we need to guard against
                // possible exceptions when accessing an external descriptor.
                try
                {
                    MaskDescriptor maskDescriptor = (MaskDescriptor)Activator.CreateInstance(t);
                    InsertMaskDescriptor(0, maskDescriptor);
                }
                catch (Exception ex)
                {
                    if (ClientUtils.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
            }
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if ((edSvc == null) || (context.Instance == null))
         {
             return(value);
         }
         if (this.columnTypePicker == null)
         {
             this.columnTypePicker = new DataGridViewColumnTypePicker();
         }
         DataGridViewColumnCollectionDialog.ListBoxItem instance = (DataGridViewColumnCollectionDialog.ListBoxItem)context.Instance;
         IDesignerHost         service          = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
         ITypeDiscoveryService discoveryService = null;
         if (service != null)
         {
             discoveryService = (ITypeDiscoveryService)service.GetService(typeof(ITypeDiscoveryService));
         }
         this.columnTypePicker.Start(edSvc, discoveryService, instance.DataGridViewColumn.GetType());
         edSvc.DropDownControl(this.columnTypePicker);
         if (this.columnTypePicker.SelectedType != null)
         {
             value = this.columnTypePicker.SelectedType;
         }
     }
     return(value);
 }
            /// <summary>
            /// Initializes a new instance of the <see cref="T:CustomTypeProvider"/> class.
            /// </summary>
            /// <param name="provider">The provider.</param>
            public CustomTypeProvider(IServiceProvider provider)
            {
                DynamicTypeService typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService));

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

                IVsHierarchy hier = DteHelper2.GetCurrentSelection(provider);

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

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

                availableTypes = new Dictionary <string, Type>();
                LoadTypes(availableTypes, discovery.GetTypes(typeof(object), false), dteProject);

                // Try loading Project references
                LoadProjectReferenceTypesFromCurrentProject(availableTypes, provider, dteProject);

                // If we don't get any type loaded, try with the rest of the projects in the current sln
                if (availableTypes.Count == 0)
                {
                    LoadTypesFromSolution(availableTypes, provider, dteProject);
                }

                EnsureKnownTypes(availableTypes);

                if (availableTypes.Count > 0 && TypesChanged != null)
                {
                    TypesChanged(this, new EventArgs());
                }
            }
Exemple #13
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                IWindowsFormsEditorService service1 = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                ITypeDiscoveryService      service2 = (ITypeDiscoveryService)provider.GetService(typeof(ITypeDiscoveryService));
                IDesignerHost           service3    = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
                IComponentChangeService service4    = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));

                if (service1 == null)
                {
                    return(value);
                }
                if (this.screenTipUI == null)
                {
                    this.screenTipUI = new ScreenTipUI(this);
                }
                //service4.OnComponentChanging(context.Instance, TypeDescriptor.GetProperties(context.Instance)["ScreenTip"]);
                this.screenTipUI.Initialize(service1, service2, service3, service4, value);
                service1.DropDownControl(this.screenTipUI);
                if (this.screenTipUI.Value != null)
                {
                    value = this.screenTipUI.Value;
                }
                this.screenTipUI.End();
                //service4.OnComponentChanged(context.Instance, TypeDescriptor.GetProperties(context.Instance)["ScreenTip"], null, null);
            }
            return(value);
        }
Exemple #14
0
        public FilteringTypeDiscoveryService(ITypeDiscoveryService decoratedTypeDiscoveryService, Func <Type, bool> filter)
        {
            ArgumentUtility.CheckNotNull("decoratedTypeDiscoveryService", decoratedTypeDiscoveryService);
            ArgumentUtility.CheckNotNull("filter", filter);

            _decoratedTypeDiscoveryService = decoratedTypeDiscoveryService;
            _filter = filter;
        }
Exemple #15
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));
        }
Exemple #16
0
        public void SetUp()
        {
            _fakeColorDefinition  = new ExtensibleEnumDefinition <Color> (MockRepository.GenerateStub <IExtensibleEnumValueDiscoveryService> ());
            _fakePlanetDefinition = new ExtensibleEnumDefinition <Planet> (MockRepository.GenerateStub <IExtensibleEnumValueDiscoveryService> ());

            _typeDiscoveryServiceStub = MockRepository.GenerateStub <ITypeDiscoveryService> ();
            _service = new TestableExtensibleEnumValueDiscoveryService(_typeDiscoveryServiceStub);
        }
Exemple #17
0
 public void End()
 {
     this.typeSvc       = (ITypeDiscoveryService)null;
     this.host          = (IDesignerHost)null;
     this.editor        = (ScreenTipEditor)null;
     this.edSvc         = (IWindowsFormsEditorService)null;
     this.originalValue = (object)null;
     this.currentValue  = (IScreenTipContent)null;
 }
Exemple #18
0
        public static FilteringTypeDiscoveryService CreateFromNamespaceBlacklist(ITypeDiscoveryService decoratedTypeDiscoveryService, params string[] blacklistedNamespaces)
        {
            ArgumentUtility.CheckNotNull("decoratedTypeDiscoveryService", decoratedTypeDiscoveryService);
            ArgumentUtility.CheckNotNullOrEmpty("blacklistedNamespaces", blacklistedNamespaces);

            return(new FilteringTypeDiscoveryService(
                       decoratedTypeDiscoveryService,
                       type => !blacklistedNamespaces.Any(blacklistedNamespace => GetNamespaceSafe(type).StartsWith(blacklistedNamespace))));
        }
Exemple #19
0
 public void End()
 {
     this.typeSvc       = null;
     this.host          = null;
     this.editor        = null;
     this.edSvc         = null;
     this.originalValue = null;
     this.currentValue  = null;
     //this.chordConverter = null;
 }
Exemple #20
0
 public void End()
 {
     this.host           = null;
     this.edSvc          = null;
     this.typeSvc        = null;
     this.defaultFilter  = null;
     this.defaultElement = null;
     this.originalValue  = null;
     this.Reset();
 }
Exemple #21
0
        public static Type[] GetCustomItemTypes(IComponent component, IServiceProvider serviceProvider)
        {
            ITypeDiscoveryService discoveryService = null;

            if (serviceProvider != null)
            {
                discoveryService = serviceProvider.GetService(typeof(ITypeDiscoveryService)) as ITypeDiscoveryService;
            }
            return(GetCustomItemTypes(component, discoveryService));
        }
 public void End()
 {
     this.host           = (IDesignerHost)null;
     this.edSvc          = (IWindowsFormsEditorService)null;
     this.typeSvc        = (ITypeDiscoveryService)null;
     this.defaultFilter  = (RadGalleryGroupFilter)null;
     this.defaultElement = (RadGalleryElement)null;
     this.originalValue  = (RadItemOwnerCollection)null;
     this.Reset();
 }
Exemple #23
0
        protected DiscoveryServiceBasedValidationCollectorReflector(
            ITypeDiscoveryService typeDiscoveryService,
            IValidatedTypeResolver validatedTypeResolver)
        {
            ArgumentUtility.CheckNotNull("typeDiscoveryService", typeDiscoveryService);
            ArgumentUtility.CheckNotNull("validatedTypeResolver", validatedTypeResolver);

            _typeDiscoveryService  = typeDiscoveryService;
            _validatedTypeResolver = validatedTypeResolver;
            _validationCollectors  = new Lazy <ILookup <Type, Type> > (GetValidationCollectors, LazyThreadSafetyMode.ExecutionAndPublication);
        }
Exemple #24
0
 public void Start(IWindowsFormsEditorService edSvc, ITypeDiscoveryService typeSvc, IDesignerHost host,
                   RadItemOwnerCollection collection, RadGalleryGroupFilter filter, RadGalleryElement owner)
 {
     this.host           = host;
     this.edSvc          = edSvc;
     this.typeSvc        = typeSvc;
     this.currentValue   = collection;
     this.originalValue  = collection;
     this.defaultFilter  = filter;
     this.defaultElement = owner;
 }
 public MaskedTextBoxDesignerActionList(MaskedTextBoxDesigner designer) : base(designer.Component)
 {
     this.maskedTextBox = (MaskedTextBox) designer.Component;
     this.discoverySvc = base.GetService(typeof(ITypeDiscoveryService)) as ITypeDiscoveryService;
     this.uiSvc = base.GetService(typeof(IUIService)) as IUIService;
     this.helpService = base.GetService(typeof(IHelpService)) as IHelpService;
     if (this.discoverySvc != null)
     {
         IUIService uiSvc = this.uiSvc;
     }
 }
Exemple #26
0
 public MaskedTextBoxDesignerActionList(MaskedTextBoxDesigner designer) : base(designer.Component)
 {
     this.maskedTextBox = (MaskedTextBox)designer.Component;
     this.discoverySvc  = base.GetService(typeof(ITypeDiscoveryService)) as ITypeDiscoveryService;
     this.uiSvc         = base.GetService(typeof(IUIService)) as IUIService;
     this.helpService   = base.GetService(typeof(IHelpService)) as IHelpService;
     if (this.discoverySvc != null)
     {
         IUIService uiSvc = this.uiSvc;
     }
 }
        public static MappingReflector CreateMappingReflector(ITypeDiscoveryService typeDiscoveryService)
        {
            ArgumentUtility.CheckNotNull("typeDiscoveryService", typeDiscoveryService);

            return(new MappingReflector(
                       typeDiscoveryService,
                       new ClassIDProvider(),
                       new ReflectionBasedMemberInformationNameResolver(),
                       new PropertyMetadataReflector(),
                       new DomainModelConstraintProvider(),
                       DomainObjectCreator));
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if ((service == null) || (context.Instance == null))
                {
                    return(value);
                }
                IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost));

                if (host == null)
                {
                    return(value);
                }

                //if (this.dataGridViewColumnCollectionDialog == null)
                //{
                //    this.dataGridViewColumnCollectionDialog = new DataGridViewColumnCollectionDialog(((DataGridView)context.Instance).Site);
                //}

                if (this.dataGridViewColumnCollectionDialog == null)
                {
                    Type type = Type.GetType("System.Windows.Forms.Design.DataGridViewColumnCollectionDialog");

                    this.dataGridViewColumnCollectionDialog = Activator.CreateInstance(
                        type,
                        BindingFlags.Instance | BindingFlags.NonPublic,
                        null,
                        new object[] { provider },
                        CultureInfo.CurrentCulture) as Form;
                }
                //this.dataGridViewColumnCollectionDialog.SetLiveDataGridView((DataGridView)context.Instance);
                MethodInfo methodInfo = this.dataGridViewColumnCollectionDialog.GetType().GetMethod("SetLiveDataGridView", BindingFlags.NonPublic | BindingFlags.Instance);
                methodInfo.Invoke(this.dataGridViewColumnCollectionDialog, new object[] { context.Instance });

                //using (DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("DataGridViewColumnCollectionTransaction")))
                using (DesignerTransaction transaction = host.CreateTransaction())
                {
                    host.RemoveService(typeof(ITypeDiscoveryService));
                    host.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
                    ITypeDiscoveryService service2 = (ITypeDiscoveryService)host.GetService(typeof(ITypeDiscoveryService));

                    if (service.ShowDialog(this.dataGridViewColumnCollectionDialog) == DialogResult.OK)
                    {
                        transaction.Commit();
                        return(value);
                    }
                    transaction.Cancel();
                }
            }
            return(value);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                IWindowsFormsEditorService windowsFormsEditorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                ITypeDiscoveryService      typeDiscoveryService      = (ITypeDiscoveryService)provider.GetService(typeof(ITypeDiscoveryService));
                IDesignerHost           designerHost           = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
                IComponentChangeService componentChangeService = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));
                ISelectionService       selectionService       = (ISelectionService)provider.GetService(typeof(ISelectionService));

                if (windowsFormsEditorService == null)
                {
                    return(value);
                }

                RadItemOwnerCollection collection1 = value as RadItemOwnerCollection;
                RadGalleryGroupFilter  filter      = context.Instance as RadGalleryGroupFilter;
                RadGalleryElement      owner       = null;

                if (collection1 == null ||
                    filter == null)
                {
                    return(value);
                }
                else
                {
                    if (filter.Owner == null && selectionService != null && selectionService.PrimarySelection != null)
                    {
                        filter.Owner = (RadGalleryElement)selectionService.PrimarySelection;
                    }
                    owner = filter.Owner;
                    if (owner == null)
                    {
                        return(value);
                    }
                }
                if (this.filteredItemsUI == null)
                {
                    this.filteredItemsUI = new FilteredItemsEditorUI();
                }
                componentChangeService.OnComponentChanging(context.Instance, TypeDescriptor.GetProperties(context.Instance)["Items"]);
                this.filteredItemsUI.Start(windowsFormsEditorService, typeDiscoveryService, designerHost, collection1, filter, owner);

                if (windowsFormsEditorService.ShowDialog(this.filteredItemsUI) == DialogResult.OK)
                {
                    this.filteredItemsUI.End();
                    value = this.filteredItemsUI.Value;
                    componentChangeService.OnComponentChanged(context.Instance, TypeDescriptor.GetProperties(context.Instance)["Items"], null, null);
                    return(value);
                }
            }
            return(value);
        }
        /// <summary>
        /// Constructor receiving a MaskedTextBox control the action list applies to.  The ITypeDiscoveryService
        /// service provider is used to populate the canned mask list control in the MaskDesignerDialog dialog and
        /// the IUIService provider is used to display the MaskDesignerDialog within VS.
        /// </summary>
        public MaskedTextBoxDesignerActionList(MaskedTextBoxDesigner designer) : base(designer.Component)
        {
            _maskedTextBox = (MaskedTextBox)designer.Component;
            _discoverySvc  = GetService(typeof(ITypeDiscoveryService)) as ITypeDiscoveryService;
            _uiSvc         = GetService(typeof(IUIService)) as IUIService;
            _helpService   = GetService(typeof(IHelpService)) as IHelpService;

            if (_discoverySvc == null || _uiSvc == null)
            {
                Debug.Fail("could not get either ITypeDiscoveryService or IUIService");
            }
        }
Exemple #31
0
        private void InitTypeDiscoveryService()
        {
            if (_discovery != null)
            {
                return;
            }
            DynamicTypeService typeService = _services.TypeService;

            if (typeService != null)
            {
                _discovery = typeService.GetTypeDiscoveryService(GetHierarchy());
            }
        }
 internal static string EditMask(ITypeDiscoveryService discoverySvc, IUIService uiSvc, MaskedTextBox instance, IHelpService helpService)
 {
     string mask = null;
     using (MaskDesignerDialog dialog = new MaskDesignerDialog(instance, helpService))
     {
         dialog.DiscoverMaskDescriptors(discoverySvc);
         DialogResult result = (uiSvc != null) ? uiSvc.ShowDialog(dialog) : dialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             mask = dialog.Mask;
             if (dialog.ValidatingType != instance.ValidatingType)
             {
                 instance.ValidatingType = dialog.ValidatingType;
             }
         }
     }
     return mask;
 }
 public void Start(IWindowsFormsEditorService edSvc, ITypeDiscoveryService discoveryService, System.Type defaultType)
 {
     this.edSvc = edSvc;
     this.typesListBox.Items.Clear();
     foreach (System.Type type in DesignerUtils.FilterGenericTypes(discoveryService.GetTypes(dataGridViewColumnType, false)))
     {
         if (((type != dataGridViewColumnType) && !type.IsAbstract) && (type.IsPublic || type.IsNestedPublic))
         {
             DataGridViewColumnDesignTimeVisibleAttribute attribute = TypeDescriptor.GetAttributes(type)[typeof(DataGridViewColumnDesignTimeVisibleAttribute)] as DataGridViewColumnDesignTimeVisibleAttribute;
             if ((attribute == null) || attribute.Visible)
             {
                 this.typesListBox.Items.Add(new ListBoxItem(type));
             }
         }
     }
     this.typesListBox.SelectedIndex = this.TypeToSelectedIndex(defaultType);
     this.selectedType = null;
     base.Width = Math.Max(base.Width, this.PreferredWidth + (SystemInformation.VerticalScrollBarWidth * 2));
 }
 public static System.Type[] GetCustomItemTypes(IComponent component, ITypeDiscoveryService discoveryService)
 {
     if (discoveryService != null)
     {
         ICollection types = discoveryService.GetTypes(toolStripItemType, false);
         ToolStripItemDesignerAvailability designerVisibility = GetDesignerVisibility(GetToolStripFromComponent(component));
         System.Type[] standardItemTypes = GetStandardItemTypes(component);
         if (designerVisibility != ToolStripItemDesignerAvailability.None)
         {
             ArrayList list = new ArrayList(types.Count);
             foreach (System.Type type in types)
             {
                 if ((type.IsAbstract || (!type.IsPublic && !type.IsNestedPublic)) || (type.ContainsGenericParameters || (type.GetConstructor(new System.Type[0]) == null)))
                 {
                     continue;
                 }
                 ToolStripItemDesignerAvailabilityAttribute attribute = (ToolStripItemDesignerAvailabilityAttribute) TypeDescriptor.GetAttributes(type)[typeof(ToolStripItemDesignerAvailabilityAttribute)];
                 if ((attribute != null) && ((attribute.ItemAdditionVisibility & designerVisibility) == designerVisibility))
                 {
                     bool flag = false;
                     foreach (System.Type type2 in standardItemTypes)
                     {
                         if (type2 == type)
                         {
                             flag = true;
                             break;
                         }
                     }
                     if (!flag)
                     {
                         list.Add(type);
                     }
                 }
             }
             if (list.Count > 0)
             {
                 System.Type[] array = new System.Type[list.Count];
                 list.CopyTo(array, 0);
                 CustomToolStripItemCount = list.Count;
                 return array;
             }
         }
     }
     CustomToolStripItemCount = 0;
     return new System.Type[0];
 }
 // Methods
 internal static string EditMask(ITypeDiscoveryService discoverySvc, IUIService uiSvc, MaskedTextBoxAdv instance, IHelpService helpService)
 {
     string mask = null;
     Type formType = Type.GetType("System.Windows.Forms.Design.MaskDesignerDialog, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
     ConstructorInfo ci = formType.GetConstructor(new Type[] { typeof(MaskedTextBox), typeof(IHelpService) });
     Form form = ci.Invoke(new object[]{instance.MaskedTextBox, helpService}) as Form;
     
     try
     {
         MethodInfo mi = formType.GetMethod("DiscoverMaskDescriptors");
         mi.Invoke(form, new object[]{discoverySvc});
         //form.DiscoverMaskDescriptors(discoverySvc);
         DialogResult result = (uiSvc != null) ? uiSvc.ShowDialog(form) : form.ShowDialog();
         if (result == DialogResult.OK)
         {
             PropertyInfo pi = formType.GetProperty("Mask");
             mask = (string)pi.GetValue(form, null);
             pi = formType.GetProperty("ValidatingType");
             Type validatingType = pi.GetValue(form, null) as Type;
             //mask = form.Mask;
             if (validatingType == instance.ValidatingType)
             {
                 return mask;
             }
             instance.ValidatingType = validatingType;
         }
     }
     finally
     {
         form.Dispose();
     }
     return mask;
 }
        /// <summary>
        /// Using the specified type discovery service, this method locates all the possible
        /// context types (currently LTS and EDM only)
        /// </summary>
        /// <param name="typeDiscoveryService">The type discovery service to use.  It cannot be null.</param>
        /// <param name="allowDbContext">A boolean indicating if DbContext is an allowable context type</param>
        /// <returns>A non-null (but possibly empty) list of candidate types</returns>
        private IEnumerable<Type> GetCandidateTypes(ITypeDiscoveryService typeDiscoveryService, bool allowDbContext, out bool foundDbContext)
        {
            foundDbContext = false;

            List<Type> candidates = new List<Type>();

            VSProject currentProject = this.ActiveProject.Object as VSProject;
            if (currentProject == null || typeDiscoveryService == null)
            {
                return candidates;
            }

            List<Reference> references = new List<Reference>();
            foreach (Reference reference in currentProject.References)
            {
                if (reference != null && !string.IsNullOrEmpty(reference.Name) && reference.Type == prjReferenceType.prjReferenceTypeAssembly)
                {
                    references.Add(reference);
                }
            }

            // Cache the value of LinqToSqlContext.EnableDataContextTypes locally since the property cannot be cached.
            bool dataContextEnabled = LinqToSqlContext.EnableDataContextTypes;

            // Get all types contained in and referenced by the project. From that list, we find the types interesting to us.
            foreach (Type t in typeDiscoveryService.GetTypes(typeof(object), true))
            {
                bool typeIsDbContext;
                if (DomainServiceClassWizard.IsContextType(t, dataContextEnabled, allowDbContext, out typeIsDbContext))
                {
                    if (IsVisibleInCurrentProject(t, currentProject, references))
                    {
                        candidates.Add(t);
                    }
                }
                foundDbContext |= typeIsDbContext;
            }

            return candidates;
        }
 /// <summary>
 /// 实例化
 /// </summary>
 /// <param name="provider"></param>
 /// <param name="baseservice"></param>
 public TypeDiscoveryService(IServiceProvider provider, ITypeDiscoveryService baseservice)
 {
     _provider = provider;
     _baseservice = baseservice;
 }
 private void InitTypeDiscoveryService()
 {
     if (_discovery != null) return;
     DynamicTypeService typeService = _services.TypeService;
     if (typeService != null)
         _discovery = typeService.GetTypeDiscoveryService(GetHierarchy());
 }
 public void DiscoverMaskDescriptors(ITypeDiscoveryService discoveryService)
 {
     if (discoveryService != null)
     {
         foreach (System.Type type in DesignerUtils.FilterGenericTypes(discoveryService.GetTypes(typeof(MaskDescriptor), false)))
         {
             if (!type.IsAbstract && type.IsPublic)
             {
                 try
                 {
                     MaskDescriptor maskDescriptor = (MaskDescriptor) Activator.CreateInstance(type);
                     this.InsertMaskDescriptor(0, maskDescriptor);
                 }
                 catch (Exception exception)
                 {
                     if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }