/// <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());
                }
            }
        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;
                    }
                }
            }
        }
Esempio n. 4
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>()));
            }
        }
        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));
                }
            }
        }
    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;
        }
    }
Esempio n. 7
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));
        }
Esempio n. 8
0
        public IEnumerable <ExtensibleEnumInfo <T> > GetValueInfos <T> (ExtensibleEnumDefinition <T> definition) where T : ExtensibleEnum <T>
        {
            ArgumentUtility.CheckNotNull("definition", definition);

            var types = _typeDiscoveryService.GetTypes(null, false).Cast <Type>();

            return(GetValueInfosForTypes(definition, types));
        }
        public void GetTypes_WithTypeDiscoveryService_IncludeGac()
        {
            Expect.Call(_serviceProvider.GetService(typeof(ITypeDiscoveryService))).Return(_typeDiscoveryService);
            Expect.Call(_typeDiscoveryService.GetTypes(typeof(object), false))
            .Return(
                new object[]
            {
                typeof(ClassWithAllDataTypes),
                typeof(SimpleValueType),
                typeof(SimpleReferenceType),
                typeof(ManualBusinessObject),
                typeof(ClassWithIdentity),
                typeof(ClassDerivedFromBindableObjectBase),
                typeof(ClassDerivedFromBindableObjectWithIdentityBase),
            });

            _mockRepository.ReplayAll();

            var         finder = new BindableObjectTypeFinder(_serviceProvider);
            List <Type> types  = finder.GetTypes(true);

            Assert.That(types, Is.EquivalentTo(new[]
            {
                typeof(ClassWithAllDataTypes),
                typeof(ClassWithIdentity),
                typeof(ClassDerivedFromBindableObjectBase),
                typeof(ClassDerivedFromBindableObjectWithIdentityBase)
            }));

            _mockRepository.VerifyAll();
        }
        private ICollection GetAllDesignerTypes(bool includeGac)
        {
            ITypeDiscoveryService typeDiscoveryService = (ITypeDiscoveryService)_serviceProvider.GetService(typeof(ITypeDiscoveryService));

            if (typeDiscoveryService == null)
            {
                return(Type.EmptyTypes);
            }
            else
            {
                return(typeDiscoveryService.GetTypes(typeof(object), !includeGac));
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Создание списка возможных типов таблицы.
 /// </summary>
 public void FillTable(ITypeDiscoveryService TypeDiscoveryService, Type type)
 {
     if (TypeDiscoveryService != null)
     {
         ICollection types = TypeDiscoveryService.GetTypes(type, false);
         foreach (Type actionType in types)
         {
             if (actionType != type)
             {
                 Add(new XPTable(actionType));
             }
         }
     }
 }
        public IEnumerable <Type> FindMixedTypes(MixinConfiguration configuration)
        {
            ArgumentUtility.CheckNotNull("configuration", configuration);

            var types = _typeDiscoveryService.GetTypes(null, false);

            s_log.InfoFormat(
                "Retrieving class contexts for {0} configured mixin targets and {1} loaded types.",
                configuration.ClassContexts.Count,
                types.Count);

            return(from t in types.Cast <Type>()
                   where !t.IsDefined(typeof(IgnoreForMixinConfigurationAttribute), false)
                   let context = configuration.GetContext(t)
                                 where context != null && !MixinTypeUtility.IsGeneratedConcreteMixedType(t) && ShouldProcessContext(context)
                                 select t);
        }
 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]);
 }
        public esDataSourceWizard(IServiceProvider provider, DataSourceControl esDataSource)
        {
            InitializeComponent();

            this.esDataSource = esDataSource;
            this.provider     = provider;
            this.helper       = new esReflectionHelper();

            //----------------------------------------------------
            // Let's see if we can load our types right up !!
            //----------------------------------------------------
            ITypeDiscoveryService discovery = null;

            if (esDataSource.Site != null)
            {
                discovery = (ITypeDiscoveryService)esDataSource.Site.GetService(typeof(ITypeDiscoveryService));
            }

            ICollection types = discovery.GetTypes(typeof(esEntityCollectionBase), true);

            foreach (Type type in types)
            {
                if (type.IsClass && !type.IsAbstract)
                {
                    if (type.IsSubclassOf(typeof(esEntityCollectionBase)))
                    {
                        try
                        {
                            esEntityCollectionBase coll = Activator.CreateInstance(type) as esEntityCollectionBase;

                            if (coll != null)
                            {
                                collections[type.Name] = coll;
                            }
                        }
                        catch { }
                    }
                }
            }

            foreach (string collectionName in collections.Keys)
            {
                this.lboxCollections.Items.Add(collectionName);
            }
        }
Esempio n. 15
0
            private void LoadTypesFromProjects(List <EnvDTE.Project> projects,
                                               Dictionary <string, Type> availableTypes,
                                               IServiceProvider provider,
                                               Project currentProject)
            {
                DynamicTypeService typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService));

                foreach (Project project in projects)
                {
                    if (project.UniqueName != currentProject.UniqueName)
                    {
                        IVsHierarchy hier = DteHelper2.GetVsHierarchy(provider, project);
                        System.Diagnostics.Debug.Assert(hier != null, "No active hierarchy is selected.");
                        ITypeDiscoveryService discovery = typeService.GetTypeDiscoveryService(hier);
                        LoadTypes(availableTypes, discovery.GetTypes(typeof(object), false), project);
                    }
                }
            }
Esempio n. 16
0
        private void AddTypes(ITypeDiscoveryService discovery, Project dteProject)
        {
            bool isWebProject = DteHelper.IsWebProject(dteProject);

            ICollection types = null;

            try
            {
                types = discovery.GetTypes(typeof(object), false);
            }
            catch
            {
                types = new ArrayList();
            }


            foreach (Type type in types)
            {
                if (!availableTypes.ContainsKey(type.FullName))
                {
                    // Web projects do not have
                    if (!isWebProject && type.Assembly.GetName().Name != (string)dteProject.Properties.Item("AssemblyName").Value)
                    {
                        availableTypes.Add(type.FullName, type);
                    }
                    else
                    {
                        availableTypes.Add(type.FullName, new ProjectType(type));
                    }
                }
            }
            if (types.Count > 0 && useProjectItemWrapper)
            {
                foreach (ProjectItem projectItem in dteProject.ProjectItems)
                {
                    Type type = BuilderProjectItemWrapper.BuildWrapper(projectItem);
                    if (type != null && !availableTypes.ContainsKey(type.FullName))
                    {
                        availableTypes.Add(type.FullName, type);
                    }
                }
            }
        }
Esempio n. 17
0
        private void DiscoverTypes()
        {
            // try to get a reference to the type discovery service
            ITypeDiscoveryService discovery = null;

            if (_control.Site != null)
            {
                discovery = (ITypeDiscoveryService)_control.Site.GetService(typeof(ITypeDiscoveryService));
            }

            if (discovery != null)
            {
                // saves the cursor and sets the wait cursor
                Cursor previousCursor = Cursor.Current;
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    // gets all types using the type discovery service
                    ICollection types = discovery.GetTypes(typeof(object), true);
                    TypeComboBox.BeginUpdate();
                    TypeComboBox.Items.Clear();
                    // adds the types to the list
                    foreach (Type type in types)
                    {
                        if (type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(",")) != "Csla" &&
                            typeof(Csla.Core.IBusinessObject).IsAssignableFrom(type))
                        {
                            string name = type.AssemblyQualifiedName;
                            if (name.Substring(name.Length - 19, 19) == "PublicKeyToken=null")
                            {
                                name = name.Substring(0, name.IndexOf(",", name.IndexOf(",") + 1));
                            }
                            TypeComboBox.Items.Add(name);
                        }
                    }
                }
                finally
                {
                    Cursor.Current = previousCursor;
                    TypeComboBox.EndUpdate();
                }
            }
        }
 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 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));
 }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
0
 public IEnumerable <Type> GetProjectReferencedTypes()
 {
     if (_projectReferencedTypes != null)
     {
         return(_projectReferencedTypes);
     }
     try
     {
         _projectReferencedTypes = _discovery.GetTypes(typeof(object), true) as IEnumerable <Type>;
     }
     catch (NullReferenceException)
     {
         //Type Discovery service isn't ready yet.
     }
     catch (Exception)
     {
         throw;
     }
     return(_projectReferencedTypes);
 }
Esempio n. 22
0
        private Type[] getReturnedTypes(IServiceProvider provider)
        {
            List <Type> res = new List <Type>();

            ITypeDiscoveryService tds = (ITypeDiscoveryService)
                                        provider.GetService(typeof(ITypeDiscoveryService));

            if (tds != null)
            {
                foreach (Type actionType in tds.GetTypes(typeof(Action), false))
                {
                    if (actionType.GetCustomAttributes(typeof(StandardActionAttribute), false).Length > 0 &&
                        !res.Contains(actionType))
                    {
                        res.Add(actionType);
                    }
                }
            }

            return(res.ToArray());
        }
Esempio n. 23
0
        /// <summary>
        /// Возвращает массив типов объектов, которые унаследованны от абстрактного класса
        /// NetworkService
        /// </summary>
        /// <param name="provider"></param>
        /// <returns>Массив типов сетевых устройств</returns>
        private Type[] GetReturnedTypes(IServiceProvider provider)
        {
            List <Type> result = new List <Type>();

            // Получаем интерфейс сервиса. Насколько я понял, это работает только
            // В design-time. В run-time tds возвращается null !!!
            ITypeDiscoveryService tds = (ITypeDiscoveryService)provider.
                                        GetService(typeof(ITypeDiscoveryService));

            if (tds != null)
            {
                // Для режима design-time
                // Нам нужны все "родственники" типа Device
                foreach (Type type in tds.GetTypes(typeof(NetworkService), false))
                {
                    if (!result.Contains(type))
                    {
                        result.Add(type);
                    }
                }
            }
            else
            {
                // Для режима run-time
                System.Reflection.Assembly asmbl = System.Reflection.Assembly.GetExecutingAssembly();

                // Нам нужны все "родственники" типа Device
                foreach (Type type in asmbl.GetTypes())
                {
                    if (type.BaseType == typeof(NetworkService))
                    {
                        if (!result.Contains(type))
                        {
                            result.Add(type);
                        }
                    }
                }
            }
            return(result.ToArray());
        }
        /// <summary>
        /// Конвертирование из строки в тип.
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            ITypeDiscoveryService discoveryService = (ITypeDiscoveryService)context.GetService(typeof(ITypeDiscoveryService));

            if (discoveryService == null)
            {
                discoveryService = (ITypeDiscoveryService)((IServiceProvider)((Component)context.Instance).Site).GetService(typeof(ITypeDiscoveryService));
            }

            if (discoveryService != null)
            {
                foreach (Type actionType in discoveryService.GetTypes(typeof(T), false))
                {
                    if (actionType.FullName == (string)value)
                    {
                        return(actionType);
                    }
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
Esempio n. 25
0
 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;
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        /// Создание начальных записей в выпадающем списке
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List <Type> result = new List <Type>();

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

            if (discoveryService == null)
            {
                discoveryService = (ITypeDiscoveryService)((IServiceProvider)((Component)context.Instance).Site).GetService(typeof(ITypeDiscoveryService));
            }

            if (discoveryService != null)
            {
                foreach (Type actionType in discoveryService.GetTypes(typeof(T), false))
                {
                    if (!result.Contains(actionType) && actionType != typeof(T))
                    {
                        result.Add(actionType);
                    }
                }
            }

            return(new StandardValuesCollection(result.ToArray()));
        }
Esempio n. 27
0
        public static ArrayList GetCommandDescriptors(ITypeDescriptorContext context)
        {
            if (_buffer != null)
            {
                return(_buffer);
            }

            ArrayList types = new ArrayList();

            try
            {
                types.Add(typeof(DCSoft.CSharpWriter.Commands.WriterCommandModuleBrowse));
                types.Add(typeof(DCSoft.CSharpWriter.Commands.WriterCommandModuleEdit));
                types.Add(typeof(DCSoft.CSharpWriter.Commands.WriterCommandModuleFile));


                //foreach (Type t in typeof(WriterCommandModule).Assembly.GetTypes())
                //{
                //    if (t.IsSubclassOf(typeof(WriterCommandModule)))
                //    {
                //        types.Add(t);
                //    }
                //    else if (t.IsSubclassOf(typeof(WriterCommand)))
                //    {
                //        types.Add(t);
                //    }
                //}
            }
            catch (Exception ext)
            {
                MessageBox.Show(ext.ToString());
            }
            //MessageBox.Show(td == null ? "null" : td.GetType().FullName);
            ITypeDiscoveryService td = (ITypeDiscoveryService)context.GetService(typeof(ITypeDiscoveryService));

            if (td != null)
            {
                //MessageBox.Show(td.GetType().FullName + " " + td.GetType().Assembly.Location );
                ICollection acts = td.GetTypes(typeof(WriterCommand), false);
                //MessageBox.Show(acts == null ? "-1" : acts.Count.ToString());
                if (acts != null)
                {
                    foreach (Type t in acts)
                    {
                        if (types.Contains(t) == false)
                        {
                            types.Add(t);
                        }
                    }

                    //types.AddRange(acts);
                }//if

                acts = td.GetTypes(typeof(CSWriterCommandModule), false);
                //MessageBox.Show(acts == null ? "no module" : acts.Count.ToString());
                if (acts != null)
                {
                    foreach (Type t in acts)
                    {
                        if (types.Contains(t) == false)
                        {
                            types.Add(t);
                        }
                    }
                    //types.AddRange(acts);
                }
            }//if
            _buffer = GetCommandDescriptors((Type[])types.ToArray(typeof(Type)));
            return(_buffer);
        }
 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];
 }
Esempio n. 29
0
        public static Type[] GetCustomItemTypes(IComponent component, ITypeDiscoveryService discoveryService)
        {
            if (discoveryService != null)
            {
                // fish out all types which derive from toolstrip item
                ICollection itemTypes = discoveryService.GetTypes(s_toolStripItemType, false /*excludeGlobalTypes*/);
                ToolStrip   toolStrip = GetToolStripFromComponent(component);
                // determine the value of the visibility attribute which matches the current toolstrip type.
                ToolStripItemDesignerAvailability currentToolStripVisibility = GetDesignerVisibility(toolStrip);
                Debug.Assert(currentToolStripVisibility != ToolStripItemDesignerAvailability.None, "Why is GetDesignerVisibility returning None?");
                // fish out the ones we've already listed.
                Type[] stockItemTypeList = GetStandardItemTypes(component);
                if (currentToolStripVisibility != ToolStripItemDesignerAvailability.None)
                {
                    ArrayList createableTypes = new ArrayList(itemTypes.Count);
                    foreach (Type t in itemTypes)
                    {
                        if (t.IsAbstract)
                        {
                            continue;
                        }
                        if (!t.IsPublic && !t.IsNestedPublic)
                        {
                            continue;
                        }
                        if (t.ContainsGenericParameters)
                        {
                            continue;
                        }
                        // Check if we have public constructor...
                        ConstructorInfo ctor = t.GetConstructor(new Type[0]);
                        if (ctor == null)
                        {
                            continue;
                        }

                        // if the visibility matches the current toolstrip type,  add it to the list of possible types to create.
                        ToolStripItemDesignerAvailabilityAttribute visiblityAttribute = (ToolStripItemDesignerAvailabilityAttribute)TypeDescriptor.GetAttributes(t)[typeof(ToolStripItemDesignerAvailabilityAttribute)];
                        if (visiblityAttribute != null && ((visiblityAttribute.ItemAdditionVisibility & currentToolStripVisibility) == currentToolStripVisibility))
                        {
                            bool isStockType = false;
                            // PERF: consider a dictionary - but this list will usually be 3-7 items.
                            foreach (Type stockType in stockItemTypeList)
                            {
                                if (stockType == t)
                                {
                                    isStockType = true;
                                    break;
                                }
                            }
                            if (!isStockType)
                            {
                                createableTypes.Add(t);
                            }
                        }
                    }

                    if (createableTypes.Count > 0)
                    {
                        Type[] createableTypesArray = new Type[createableTypes.Count];
                        createableTypes.CopyTo(createableTypesArray, 0);
                        s_customToolStripItemCount = createableTypes.Count;
                        return(createableTypesArray);
                    }
                }
            }
            s_customToolStripItemCount = 0;
            return(new Type[0]);
        }
 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;
                     }
                 }
             }
         }
     }
 }
Esempio n. 31
0
        private ListBox CreateListBox(ITypeDescriptorContext context, object value)
        {
            ListBox listBox = new ListBox();

            listBox.SelectedValueChanged += new EventHandler(listBox_SelectedValueChanged);
            listBox.Dock        = DockStyle.Fill;
            listBox.BorderStyle = BorderStyle.None;
            listBox.ItemHeight  = 13;

            listBox.Items.Add("(none)");

            // Load standard shapes
            if (context.Container != null)
            {
                ITypeDiscoveryService discoveryService = (ITypeDiscoveryService)context.GetService(typeof(ITypeDiscoveryService));
                foreach (Type type in discoveryService.GetTypes(typeof(ElementShape), false))
                {
                    if (type != typeof(CustomShape) && !type.IsAbstract && type.IsPublic)
                    {
                        listBox.Items.Add(type.Name);
                        shapes.Add(type);

                        if (value != null && value.GetType() == type)
                        {
                            listBox.SelectedIndex = listBox.Items.Count - 1;
                        }
                    }
                }
            }
            else
            {
                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        if (!IsTelerikAssembly(assembly))
                        {
                            continue;
                        }
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (type.IsClass && type.IsPublic && !type.IsAbstract &&
                                typeof(ElementShape).IsAssignableFrom(type) &&
                                type != typeof(CustomShape))
                            {
                                listBox.Items.Add(type.Name);
                                shapes.Add(type);

                                if (value != null && value.GetType() == type)
                                {
                                    listBox.SelectedIndex = listBox.Items.Count - 1;
                                }
                            }
                        }
                    }
                    catch (ReflectionTypeLoadException e)
                    {
                        string message = e.Message + "\n\nLoader Exceptions:\n";
                        for (int i = 0; i < Math.Min(MaxLoaderExceptionsInMessageBox, e.LoaderExceptions.Length); i++)
                        {
                            message += e.LoaderExceptions[i].Message + "\n";
                        }
                        if (e.LoaderExceptions.Length > MaxLoaderExceptionsInMessageBox)
                        {
                            message += "More...";
                        }
                        MessageBox.Show(message, assembly.FullName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, assembly.FullName);
                    }
                }
            }

            // Load custom shape components
            if (context.Container != null)
            {
                foreach (IComponent component in context.Container.Components)
                {
                    if (component is CustomShape)
                    {
                        listBox.Items.Add(component.Site.Name);
                        shapes.Add(component);

                        if (component == value)
                        {
                            listBox.SelectedIndex = listBox.Items.Count - 1;
                        }
                    }
                }

                listBox.Items.Add("Create new custom shape ...");
                if (value != null && value is CustomShape)
                {
                    listBox.Items.Add("Edit points ...");
                }
            }
            else
            {
                if (value != null && value is CustomShape)
                {
                    listBox.Items.Add("Edit points ...");
                }
                else
                {
                    listBox.Items.Add("Create new custom shape ...");
                }
            }


            return(listBox);
        }
Esempio n. 32
0
 /// <summary>
 /// Gets the default service configuration for the types returned by the given <see cref="ITypeDiscoveryService"/>.
 /// </summary>
 /// <returns>A <see cref="ServiceConfigurationEntry"/> for each serviceType that has implementations with a <see cref="ImplementationForAttribute"/> applied.
 /// Types without the attribute are ignored.</returns>
 public IEnumerable <ServiceConfigurationEntry> GetDefaultConfiguration()
 {
     return(GetDefaultConfiguration(_typeDiscoveryService.GetTypes(null, _excludeGlobalTypesForDefaultConfiguration).Cast <Type>()));
 }
        /// <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;
        }
Esempio n. 34
0
 private IEnumerable <Type> GetDomainObjectTypes()
 {
     return((from type in _typeDiscoveryService.GetTypes(typeof(DomainObject), false).Cast <Type>()
             where !ReflectionUtility.IsTypeIgnoredForMappingConfiguration(type)
             select type).Distinct());
 }