Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/11/09 18:25:15 (14 years ago)
Author:
gkronber
Message:

Refactored class Loader in plugin infrastructure. #799

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/DiscoveryService.cs

    r2234 r2481  
    3131  public class DiscoveryService {
    3232
    33     public PluginInfo[] Plugins {
    34       get {
    35         PluginInfo[] plugins = new PluginInfo[PluginManager.Manager.LoadedPlugins.Count];
    36         PluginManager.Manager.LoadedPlugins.CopyTo(plugins, 0);
    37         return plugins;
    38       }
    39     }
     33    //public PluginDescription[] Plugins {
     34    //  get {
     35    //    PluginInfo[] plugins = new PluginInfo[PluginManager.Manager.LoadedPlugins.Count];
     36    //    PluginManager.Manager.LoadedPlugins.CopyTo(plugins, 0);
     37    //    return plugins;
     38    //  }
     39    //}
    4040
    4141    /// <summary>
     
    8787    }
    8888
    89     /// <summary>
    90     /// Finds all types that are subtypes or equal to the specified type if they are part of the given
    91     /// <paramref name="plugin"/>.
    92     /// </summary>
    93     /// <param name="type">Most general type for which to find matching types.</param>
    94     /// <param name="plugin">The plugin the subtypes must be part of.</param>
    95     /// <returns>The found types as array.</returns>
    96     public Type[] GetTypes(Type type, PluginInfo plugin) {
    97       Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
    98       List<Type> types = new List<Type>();
    99       foreach (Assembly asm in assemblies) {
    100         if (plugin.Assemblies.Contains(asm.Location)) {
    101           Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) {
    102             types.Add(t);
    103           });
    104         }
    105       }
     89    ///// <summary>
     90    ///// Finds all types that are subtypes or equal to the specified type if they are part of the given
     91    ///// <paramref name="plugin"/>.
     92    ///// </summary>
     93    ///// <param name="type">Most general type for which to find matching types.</param>
     94    ///// <param name="plugin">The plugin the subtypes must be part of.</param>
     95    ///// <returns>The found types as array.</returns>
     96    //public Type[] GetTypes(Type type, PluginInfo plugin) {
     97    //  Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     98    //  List<Type> types = new List<Type>();
     99    //  foreach (Assembly asm in assemblies) {
     100    //    if (plugin.Assemblies.Contains(asm.Location)) {
     101    //      Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) {
     102    //        types.Add(t);
     103    //      });
     104    //    }
     105    //  }
    106106
    107       return types.ToArray();
    108     }
     107    //  return types.ToArray();
     108    //}
    109109
    110     /// <summary>
    111     /// Gets instances of all types that implement the specified interface only in the given assembly.
    112     /// </summary>
    113     /// <typeparam name="T">Interface type.</typeparam>
    114     /// <param name="assembly">Assembly that should be searched for types.</param>
    115     /// <returns>The found instances as array.</returns>
    116     internal T[] GetInstances<T>(Assembly assembly) {
    117       Type[] types = GetTypes(typeof(T), assembly);
    118       List<T> instances = new List<T>();
    119       foreach (Type t in types) {
    120         if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
    121           instances.Add((T)Activator.CreateInstance(t));
    122         }
    123       }
    124       return instances.ToArray();
    125     }
     110    ///// <summary>
     111    ///// Gets instances of all types that implement the specified interface only in the given assembly.
     112    ///// </summary>
     113    ///// <typeparam name="T">Interface type.</typeparam>
     114    ///// <param name="assembly">Assembly that should be searched for types.</param>
     115    ///// <returns>The found instances as array.</returns>
     116    //internal T[] GetInstances<T>(Assembly assembly) {
     117    //  Type[] types = GetTypes(typeof(T), assembly);
     118    //  List<T> instances = new List<T>();
     119    //  foreach (Type t in types) {
     120    //    if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) {
     121    //      instances.Add((T)Activator.CreateInstance(t));
     122    //    }
     123    //  }
     124    //  return instances.ToArray();
     125    //}
    126126
    127127    /// <summary>
     
    141141    }
    142142
    143     /// <summary>
    144     /// Gets the plugin of the given <paramref name="type"/>.
    145     /// </summary>
    146     /// <param name="type"></param>
    147     /// <returns>The found plugin or <c>null</c>.</returns>
    148     public PluginInfo GetDeclaringPlugin(Type type) {
    149       foreach (PluginInfo info in PluginManager.Manager.LoadedPlugins) {
    150         if (info.Assemblies.Contains(type.Assembly.Location)) return info;
    151       }
    152       return null;
    153     }
     143    ///// <summary>
     144    ///// Gets the plugin of the given <paramref name="type"/>.
     145    ///// </summary>
     146    ///// <param name="type"></param>
     147    ///// <returns>The found plugin or <c>null</c>.</returns>
     148    //public PluginInfo GetDeclaringPlugin(Type type) {
     149    //  foreach (PluginInfo info in PluginManager.Manager.LoadedPlugins) {
     150    //    if (info.Assemblies.Contains(type.Assembly.Location)) return info;
     151    //  }
     152    //  return null;
     153    //}
    154154  }
    155155}
Note: See TracChangeset for help on using the changeset viewer.