示例#1
0
        public Type[] GetTypes()
        {
            EnsureCurrentTypes();

            bool hasTypeLoadErrors = false;

            this.typeLoadErrors.Clear(); //clear all old errors

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

            // Design time types
            foreach (Type type in this.designTimeTypes.Values)
            {
                typeList.Add(type);
            }

            foreach (DictionaryEntry dictionaryEntry in this.assemblyLoaders)
            {
                AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader;
                try
                {
                    typeList.AddRange(assemblyLoader.GetTypes());
                }
                catch (Exception e)
                {
                    ReflectionTypeLoadException typeLoadException = e as ReflectionTypeLoadException;
                    if (typeLoadException != null)
                    {
                        //we should at least add the types that did get loaded
                        foreach (Type type in typeLoadException.Types)
                        {
                            if (type != null)
                            {
                                typeList.Add(type);
                            }
                        }
                    }

                    //we should have the latest exception for every assembly (user might have copied required dlls over)
                    if (this.typeLoadErrors.Contains(dictionaryEntry.Key))
                    {
                        this.typeLoadErrors.Remove(dictionaryEntry.Key);
                    }

                    this.typeLoadErrors[dictionaryEntry.Key] = e;
                    hasTypeLoadErrors = true;
                }
            }

            foreach (DictionaryEntry dictionaryEntry in this.rawAssemblyLoaders)
            {
                AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader;
                try
                {
                    typeList.AddRange(assemblyLoader.GetTypes());
                }
                catch (Exception e)
                {
                    ReflectionTypeLoadException typeLoadException = e as ReflectionTypeLoadException;
                    if (typeLoadException != null)
                    {
                        //we should at least add the types that did get loaded
                        foreach (Type type in typeLoadException.Types)
                        {
                            if (type != null)
                            {
                                typeList.Add(type);
                            }
                        }
                    }
                    //we should have the latest exception for every assembly (user might have copied required dlls over)
                    if (this.typeLoadErrors.Contains(dictionaryEntry.Key))
                    {
                        this.typeLoadErrors.Remove(dictionaryEntry.Key);
                    }

                    this.typeLoadErrors[dictionaryEntry.Key] = e;
                    hasTypeLoadErrors = true;
                }
            }

            if (hasTypeLoadErrors)
            {
                if (this.TypeLoadErrorsChanged != null)
                {
                    FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty });
                }
            }

            return(typeList.ToArray());
        }
示例#2
0
        public Type[] GetTypes()
        {
            this.EnsureCurrentTypes();
            bool flag = false;

            this.typeLoadErrors.Clear();
            List <Type> list = new List <Type>();

            foreach (Type type in this.designTimeTypes.Values)
            {
                list.Add(type);
            }
            foreach (DictionaryEntry entry in this.assemblyLoaders)
            {
                AssemblyLoader loader = entry.Value as AssemblyLoader;
                try
                {
                    list.AddRange(loader.GetTypes());
                }
                catch (Exception exception)
                {
                    ReflectionTypeLoadException exception2 = exception as ReflectionTypeLoadException;
                    if (exception2 != null)
                    {
                        foreach (Type type2 in exception2.Types)
                        {
                            if (type2 != null)
                            {
                                list.Add(type2);
                            }
                        }
                    }
                    if (this.typeLoadErrors.Contains(entry.Key))
                    {
                        this.typeLoadErrors.Remove(entry.Key);
                    }
                    this.typeLoadErrors[entry.Key] = exception;
                    flag = true;
                }
            }
            foreach (DictionaryEntry entry2 in this.rawAssemblyLoaders)
            {
                AssemblyLoader loader2 = entry2.Value as AssemblyLoader;
                try
                {
                    list.AddRange(loader2.GetTypes());
                }
                catch (Exception exception3)
                {
                    ReflectionTypeLoadException exception4 = exception3 as ReflectionTypeLoadException;
                    if (exception4 != null)
                    {
                        foreach (Type type3 in exception4.Types)
                        {
                            if (type3 != null)
                            {
                                list.Add(type3);
                            }
                        }
                    }
                    if (this.typeLoadErrors.Contains(entry2.Key))
                    {
                        this.typeLoadErrors.Remove(entry2.Key);
                    }
                    this.typeLoadErrors[entry2.Key] = exception3;
                    flag = true;
                }
            }
            if (flag && (this.TypeLoadErrorsChanged != null))
            {
                FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty });
            }
            return(list.ToArray());
        }