1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections;
6
using System.Collections.Generic;
7
using System.ComponentModel.Design;
8
using System.Reflection;
10
using ICSharpCode.Core;
11
using ICSharpCode.SharpDevelop.Dom;
13
namespace ICSharpCode.Reports.Addin
15
public class TypeDiscoveryService : ITypeDiscoveryService
17
public TypeDiscoveryService()
22
/// Returns the list of available types.
24
/// <param name="baseType">The base type to match. Can be null.</param>
25
/// <param name="excludeGlobalTypes">Determines whether types
26
/// from all referenced assemblies should be checked.</param>
27
public ICollection GetTypes(Type baseType, bool excludeGlobalTypes)
29
List<Type> types = new List<Type>();
31
if (baseType == null) {
32
baseType = typeof(object);
35
LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName
36
+ "excludeGlobalTypes=" + excludeGlobalTypes.ToString());
37
//seek in all assemblies
38
//allow to work designers like columns editor in datagridview
39
// Searching types can cause additional assemblies to be loaded, so we need to use
40
// ToArray to prevent an exception if the collection changes.
41
foreach (Assembly asm in TypeResolutionService.DesignerAssemblies.ToArray()) {
42
if (excludeGlobalTypes) {
43
if (GacInterop.IsWithinGac(asm.Location)) {
47
AddDerivedTypes(baseType, asm, types);
49
LoggingService.Debug("TypeDiscoveryService returns " + types.Count + " types");
51
// TODO - Don't look in all assemblies.
52
// Should use the current project and its referenced assemblies
53
// as well as System.Windows.Forms.
59
/// Gets the types derived from baseType from the assembly and adds them to the list.
61
void AddDerivedTypes(Type baseType, Assembly assembly, IList<Type> list)
63
foreach (Type t in assembly.GetExportedTypes()) {
64
if (t.IsSubclassOf(baseType)) {
65
//LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName);