Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/11 11:45:18 (12 years ago)
Author:
gkronber
Message:

#1081 merged r7103:7209 from trunk into time series branch

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r7069 r7213  
    148148    internal static IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class {
    149149      List<T> instances = new List<T>();
    150       foreach (Type t in GetTypes(typeof(T), plugin, true)) {
     150      foreach (Type t in GetTypes(typeof(T), plugin, onlyInstantiable: true, includeGenericTypeDefinitions: false)) {
    151151        T instance = null;
    152152        try { instance = (T)Activator.CreateInstance(t); }
     
    164164    private static IEnumerable<T> GetInstances<T>(Assembly asm) where T : class {
    165165      List<T> instances = new List<T>();
    166       foreach (Type t in GetTypes(typeof(T), asm, true)) {
     166      foreach (Type t in GetTypes(typeof(T), asm, onlyInstantiable: true, includeGenericTypeDefinitions: false)) {
    167167        T instance = null;
    168168        try { instance = (T)Activator.CreateInstance(t); }
     
    189189    internal static IEnumerable<object> GetInstances(Type type) {
    190190      List<object> instances = new List<object>();
    191       foreach (Type t in GetTypes(type, true)) {
     191      foreach (Type t in GetTypes(type, onlyInstantiable: true, includeGenericTypeDefinitions: false)) {
    192192        object instance = null;
    193193        try { instance = Activator.CreateInstance(t); }
     
    203203    /// <param name="type">Most general type for which to find matching types.</param>
    204204    /// <param name="onlyInstantiable">Return only types that are instantiable
     205    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    205206    /// (interfaces, abstract classes... are not returned)</param>
    206207    /// <returns>Enumerable of the discovered types.</returns>
    207     internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) {
     208    internal static IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
    208209      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    209              from t in GetTypes(type, asm, onlyInstantiable)
     210             from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions)
    210211             select t;
    211212    }
    212213
    213     internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool assignableToAllTypes) {
    214       IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable);
     214    internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) {
     215      IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable, includeGenericTypeDefinitions);
    215216      foreach (Type type in types.Skip(1)) {
    216         IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable);
     217        IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions);
    217218        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
    218219        else result = result.Union(discoveredTypes);
     
    228229    /// <param name="pluginDescription">The plugin the subtypes must be part of.</param>
    229230    /// <param name="onlyInstantiable">Return only types that are instantiable
     231    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    230232    /// (interfaces, abstract classes... are not returned)</param>
    231233    /// <returns>Enumerable of the discovered types.</returns>
    232     internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable) {
     234    internal static IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
    233235      PluginDescription pluginDesc = (PluginDescription)pluginDescription;
    234236      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    235237             where !IsDynamicAssembly(asm)
    236238             where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase))
    237              from t in GetTypes(type, asm, onlyInstantiable)
     239             from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions)
    238240             select t;
    239241    }
    240242
    241     internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription pluginDescription, bool onlyInstantiable, bool assignableToAllTypes) {
    242       IEnumerable<Type> result = GetTypes(types.First(), pluginDescription, onlyInstantiable);
     243    internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription pluginDescription, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) {
     244      IEnumerable<Type> result = GetTypes(types.First(), pluginDescription, onlyInstantiable, includeGenericTypeDefinitions);
    243245      foreach (Type type in types.Skip(1)) {
    244         IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable);
     246        IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable, includeGenericTypeDefinitions);
    245247        if (assignableToAllTypes) result = result.Intersect(discoveredTypes);
    246248        else result = result.Union(discoveredTypes);
     
    260262    /// <param name="onlyInstantiable">Return only types that are instantiable
    261263    /// (interfaces, abstract classes...  are not returned)</param>
     264    /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param>
    262265    /// <returns>Enumerable of the discovered types.</returns>
    263     private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
     266    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
    264267      var buildTypes = from t in assembly.GetTypes()
    265268                       where !IsNonDiscoverableType(t)
     
    270273
    271274      return from t in buildTypes
    272              where onlyInstantiable == false || !t.IsGenericTypeDefinition
     275             where includeGenericTypeDefinitions || !t.IsGenericTypeDefinition
    273276             select t;
    274277    }
     
    316319    }
    317320
    318     IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable) {
    319       return GetTypes(type, onlyInstantiable);
    320     }
    321     IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool assignableToAllTypes) {
    322       return GetTypes(types, onlyInstantiable, assignableToAllTypes);
    323     }
    324 
    325     IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
    326       return GetTypes(type, plugin, onlyInstantiable);
    327     }
    328     IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool assignableToAllTypes) {
    329       return GetTypes(types, plugin, onlyInstantiable, assignableToAllTypes);
     321    IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
     322      return GetTypes(type, onlyInstantiable, includeGenericTypeDefinitions);
     323    }
     324    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) {
     325      return GetTypes(types, onlyInstantiable, includeGenericTypeDefinitions, assignableToAllTypes);
     326    }
     327
     328    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable, bool includeGenericTypeDefinitions) {
     329      return GetTypes(type, plugin, onlyInstantiable, includeGenericTypeDefinitions);
     330    }
     331    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool includeGenericTypeDefinitions, bool assignableToAllTypes) {
     332      return GetTypes(types, plugin, onlyInstantiable, includeGenericTypeDefinitions, assignableToAllTypes);
    330333    }
    331334
Note: See TracChangeset for help on using the changeset viewer.