Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/18/09 01:08:12 (15 years ago)
Author:
mkommend
Message:

implemented changes regarding detection of view types and default views as discussed with SWA (ticket #771)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r2433 r2437  
    8484
    8585    public static IEnumerable<Type> GetViewTypes(Type viewableType) {
    86       List<Type> viewsForType;
    87       if (!views.ContainsKey(viewableType))
    88         viewsForType = new List<Type>();
    89       else
    90         viewsForType = views[viewableType];
    91 
    92       if (viewableType.BaseType != null)
    93         viewsForType.AddRange(GetViewTypes(viewableType.BaseType));
     86      List<Type> viewsForType = new List<Type>();
     87      foreach (KeyValuePair<Type, List<Type>> v in views) {
     88        if (v.Key.IsAssignableFrom(viewableType))
     89          viewsForType.AddRange(v.Value);
     90      }
    9491      return viewsForType.Distinct();
    9592    }
     
    10097
    10198    public static Type GetDefaultViewType(Type viewableType) {
    102       if (!defaultViews.ContainsKey(viewableType))
    103         return null;
    104       return defaultViews[viewableType];
     99      if (!defaultViews.ContainsKey(viewableType)) {
     100        List<Type> temp = defaultViews.Keys.Where(x => x.IsAssignableFrom(viewableType)).ToList();
     101        if (temp.Count == 0)
     102          return null;
     103        else if (temp.Count == 1)
     104          return defaultViews[temp[0]];
     105        else {
     106          temp.Sort(delegate(Type t1, Type t2) {
     107            if (t1.IsAssignableFrom(t2))
     108              return 1;
     109            return -1;
     110          }
     111          );
     112          if (!temp[0].IsAssignableFrom(temp[1]) && !temp[1].IsAssignableFrom(temp[0]))
     113            throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ".");
     114          else
     115            return defaultViews[temp[0]];
     116        }
     117      } else
     118        return defaultViews[viewableType];
    105119    }
    106120
     
    110124        return null;
    111125      else
    112         return (IView<T>) Activator.CreateInstance(t);
     126        return (IView<T>)Activator.CreateInstance(t);
    113127    }
    114128  }
Note: See TracChangeset for help on using the changeset viewer.