Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/30/09 11:06:10 (14 years ago)
Author:
mkommend
Message:

implemented last changes in MainForm as discussed with SWA (ticket #771)

File:
1 edited

Legend:

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

    r2444 r2456  
    5656                views[viewableType].Add(t);
    5757
    58                 object[] attributes = t.GetCustomAttributes(typeof(DefaultView), false);
    59                 if (attributes != null && attributes.Length == 1) {
     58                if (DefaultViewAttribute.IsDefaultView(t)) {
    6059                  if (defaultViews.ContainsKey(viewableType))
    6160                    throw new ArgumentException("DefaultView for type " + viewableType + " is " + defaultViews[viewableType] +
     
    7473      IEnumerable<Type> interfaceTypes =
    7574       from type in t.GetInterfaces()
    76        where type.Namespace == "HeuristicLab.MainForm" && type.Name.StartsWith("IView")  &&
     75       where type.Namespace == "HeuristicLab.MainForm" && type.Name.StartsWith("IView") &&
    7776             type.IsGenericType && !type.IsGenericTypeDefinition
    7877       select type;
    7978
    80       foreach (Type interfaceType in interfaceTypes) {     
    81           yield return interfaceType.GetGenericArguments()[0];
     79      foreach (Type interfaceType in interfaceTypes) {
     80        yield return interfaceType.GetGenericArguments()[0];
    8281      }
    8382    }
     
    105104
    106105    public static Type GetDefaultViewType(Type viewableType) {
     106      //check if viewableType has a default view
    107107      if (defaultViews.ContainsKey(viewableType))
    108108        return defaultViews[viewableType];
    109       else {
    110         List<Type> temp = (from t in defaultViews.Keys
    111                            where t.IsAssignableFrom(viewableType)
    112                            select t).ToList();
    113         //no assignable type found
    114         if (temp.Count == 0)
    115           return null;
    116         //only one assignable type found => return this one
    117         else if (temp.Count == 1)
    118           return defaultViews[temp[0]];
    119         //more assignable types found => sort the types according to their assignable types
    120         //and return most specific type => except there is a conflict
    121         else {
    122           temp.Sort(delegate(Type t1, Type t2) {
    123             if (t1.IsAssignableFrom(t2))
    124               return 1;
    125             else if (t2.IsAssignableFrom(t1))
    126               return -1;
    127             else
    128               return 0;
    129           }
    130           );
    131           if (temp[1].IsAssignableFrom(temp[0]))
    132             return defaultViews[temp[0]];
    133           else
    134             throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ".");
    135         }
     109
     110      //check base classes for default view
     111      Type type = viewableType;
     112      while (type.BaseType != null && !defaultViews.ContainsKey(type)) {
     113        type = type.BaseType;
    136114      }
     115      if (defaultViews.ContainsKey(type))
     116        return defaultViews[type];
     117
     118      //check if exact one implemented interface has a default view
     119      List<Type> temp = (from t in defaultViews.Keys
     120                         where t.IsAssignableFrom(viewableType) && t.IsInterface
     121                         select t).ToList();
     122      if (temp.Count == 1)
     123        return defaultViews[temp[0]];
     124      //more than one default view for implemented interfaces are found
     125      if (temp.Count > 1)
     126        throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ". Because more than one implemented interfaces have a default view.");
     127      return null;
    137128    }
    138129
Note: See TracChangeset for help on using the changeset viewer.