Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/09 10:02:26 (15 years ago)
Author:
mkommend
Message:

implemented non-generic GetInstances method in the DiscoveryService (ticket #718)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/DiscoveryService.cs

    r1189 r2234  
    4747      Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
    4848      List<Type> types = new List<Type>();
    49       foreach(Assembly asm in assemblies) {
     49      foreach (Assembly asm in assemblies) {
    5050        Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) {
    5151          types.Add(t);
     
    6363      Type[] types = GetTypes(typeof(T));
    6464      List<T> instances = new List<T>();
    65       foreach(Type t in types) {
    66         if(!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
     65      foreach (Type t in types) {
     66        if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
    6767          instances.Add((T)Activator.CreateInstance(t));
     68        }
     69      }
     70      return instances.ToArray();
     71    }
     72
     73    /// <summary>
     74    /// Creates an instance of all types that are subtypes or the same type of the specified type
     75    /// </summary>
     76    /// <typeparam name="type">Most general type.</typeparam>
     77    /// <returns>The created instances as array.</returns>
     78    public object[] GetInstances(Type type) {
     79      Type[] types = GetTypes(type);
     80      List<object> instances = new List<object>();
     81      foreach (Type t in types) {
     82        if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
     83          instances.Add(Activator.CreateInstance(t));
    6884        }
    6985      }
     
    8197      Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
    8298      List<Type> types = new List<Type>();
    83       foreach(Assembly asm in assemblies) {
    84         if(plugin.Assemblies.Contains(asm.Location)) {
     99      foreach (Assembly asm in assemblies) {
     100        if (plugin.Assemblies.Contains(asm.Location)) {
    85101          Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) {
    86102            types.Add(t);
     
    101117      Type[] types = GetTypes(typeof(T), assembly);
    102118      List<T> instances = new List<T>();
    103       foreach(Type t in types) {
    104         if(!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
     119      foreach (Type t in types) {
     120        if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
    105121          instances.Add((T)Activator.CreateInstance(t));
    106122        }
     
    117133    internal Type[] GetTypes(Type type, Assembly assembly) {
    118134      List<Type> types = new List<Type>();
    119       foreach(Type t in assembly.GetTypes()) {
    120         if(type.IsAssignableFrom(t)) {
     135      foreach (Type t in assembly.GetTypes()) {
     136        if (type.IsAssignableFrom(t)) {
    121137          types.Add(t);
    122138        }
     
    131147    /// <returns>The found plugin or <c>null</c>.</returns>
    132148    public PluginInfo GetDeclaringPlugin(Type type) {
    133       foreach(PluginInfo info in PluginManager.Manager.LoadedPlugins) {
    134         if(info.Assemblies.Contains(type.Assembly.Location)) return info;
     149      foreach (PluginInfo info in PluginManager.Manager.LoadedPlugins) {
     150        if (info.Assemblies.Contains(type.Assembly.Location)) return info;
    135151      }
    136152      return null;
Note: See TracChangeset for help on using the changeset viewer.