Ejemplo n.º 1
0
        internal static void AddTypeProviderAssembliesFromRegistry(TypeProvider typeProvider, IServiceProvider serviceProvider)
        {
            if (typeProvider == null)
            {
                throw new ArgumentNullException("typeProvider");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            RegistryKey key = Registry.CurrentUser.OpenSubKey(TypeProviderRegistryKeyPath);

            if (key != null)
            {
                ITypeProviderCreator service = serviceProvider.GetService(typeof(ITypeProviderCreator)) as ITypeProviderCreator;
                foreach (string str in (string[])key.GetValue(TypeProviderAssemblyRegValueName))
                {
                    try
                    {
                        if (service != null)
                        {
                            bool     flag = true;
                            Assembly transientAssembly = service.GetTransientAssembly(AssemblyName.GetAssemblyName(str));
                            if (transientAssembly == null)
                            {
                                continue;
                            }
                            System.Type[] types = transientAssembly.GetTypes();
                            int           index = 0;
                            while (index < types.Length)
                            {
                                System.Type type = types[index];
                                if (typeProvider.GetType(type.AssemblyQualifiedName) != null)
                                {
                                    flag = false;
                                }
                                break;
                            }
                            if (flag)
                            {
                                typeProvider.AddAssembly(transientAssembly);
                            }
                            continue;
                        }
                        typeProvider.AddAssemblyReference(str);
                    }
                    catch
                    {
                    }
                }
                key.Close();
            }
        }
Ejemplo n.º 2
0
        //

        protected override IComponent[] CreateComponentsCore(IDesignerHost host)
        {
            Type typeOfComponent = GetType(host, AssemblyName, TypeName, true);

            if (typeOfComponent == null && host != null)
            {
                typeOfComponent = host.GetType(TypeName);
            }

            if (typeOfComponent == null)
            {
                ITypeProviderCreator tpc = null;
                if (host != null)
                {
                    tpc = (ITypeProviderCreator)host.GetService(typeof(ITypeProviderCreator));
                }
                if (tpc != null)
                {
                    System.Reflection.Assembly assembly = tpc.GetTransientAssembly(this.AssemblyName);
                    if (assembly != null)
                    {
                        typeOfComponent = assembly.GetType(this.TypeName);
                    }
                }

                if (typeOfComponent == null)
                {
                    typeOfComponent = GetType(host, AssemblyName, TypeName, true);
                }
            }

            ArrayList comps = new ArrayList();

            if (typeOfComponent != null)
            {
                if (typeof(IComponent).IsAssignableFrom(typeOfComponent))
                {
                    comps.Add(TypeDescriptor.CreateInstance(null, typeOfComponent, null, null));
                }
            }

            IComponent[] temp = new IComponent[comps.Count];
            comps.CopyTo(temp, 0);
            return(temp);
        }
        protected override IComponent[] CreateComponentsCore(IDesignerHost host)
        {
            Type c = this.GetType(host, base.AssemblyName, base.TypeName, true);

            if ((c == null) && (host != null))
            {
                c = host.GetType(base.TypeName);
            }
            if (c == null)
            {
                ITypeProviderCreator service = null;
                if (host != null)
                {
                    service = (ITypeProviderCreator)host.GetService(typeof(ITypeProviderCreator));
                }
                if (service != null)
                {
                    Assembly transientAssembly = service.GetTransientAssembly(base.AssemblyName);
                    if (transientAssembly != null)
                    {
                        c = transientAssembly.GetType(base.TypeName);
                    }
                }
                if (c == null)
                {
                    c = this.GetType(host, base.AssemblyName, base.TypeName, true);
                }
            }
            ArrayList list = new ArrayList();

            if ((c != null) && typeof(IComponent).IsAssignableFrom(c))
            {
                list.Add(TypeDescriptor.CreateInstance(null, c, null, null));
            }
            IComponent[] array = new IComponent[list.Count];
            list.CopyTo(array, 0);
            return(array);
        }