Changeset 3268


Ignore:
Timestamp:
04/05/10 14:50:55 (11 years ago)
Author:
mkommend
Message:

corrected lookup of default views in MainFormManager (ticket #958)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r3255 r3268  
    9595
    9696        foreach (Type viewType in viewTypes.ToList()) {
    97           if((viewType != defaultViewType) && viewTypes.Any(t => t.IsSubclassOf(viewType)))
     97          if ((viewType != defaultViewType) && viewTypes.Any(t => t.IsSubclassOf(viewType)))
    9898            viewTypes.Remove(viewType);
    9999        }
     
    114114      Type type = contentType;
    115115      while (type != null) {
     116        //check classes
    116117        foreach (Type defaultContentType in defaultViews.Keys) {
    117118          if (type == defaultContentType || type.CheckGenericTypes(defaultContentType))
    118119            return TransformGenericTypeDefinition(defaultViews[defaultContentType], contentType);
    119120        }
     121
     122        //check interfaces
     123        IEnumerable<Type> nonInheritedInterfaces = type.GetInterfaces().Where(i => !i.IsAssignableFrom(type.BaseType));
     124        List<Type> defaultViewList = new List<Type>();
     125        foreach (Type defaultContentType in defaultViews.Keys) {
     126          if (nonInheritedInterfaces.Contains(defaultContentType) || nonInheritedInterfaces.Any(i => i.CheckGenericTypes(defaultContentType)))
     127            defaultViewList.Add(defaultViews[defaultContentType]);
     128        }
     129
     130        //return only most spefic view as default view
     131        foreach (Type viewType in defaultViewList.ToList()) {
     132          if (defaultViewList.Any(t => t.IsSubclassOf(viewType)))
     133            defaultViewList.Remove(viewType);
     134        }
     135
     136        if (defaultViewList.Count == 1)
     137          return TransformGenericTypeDefinition(defaultViewList[0], contentType);
     138        else if (defaultViewList.Count > 1)
     139          throw new InvalidOperationException("Could not determine which is the default view for type " + contentType.ToString() + ". Because more than one implemented interfaces have a default view.");
     140
    120141        type = type.BaseType;
    121142      }
    122143
    123       //check if exactly one implemented interface has a default view
    124       List<Type> temp = (from t in defaultViews.Keys
    125                          where t.IsInterface && contentType.IsAssignableTo(t)
    126                          select t).ToList();
    127       if (temp.Count == 1)
    128         return TransformGenericTypeDefinition(defaultViews[temp[0]], contentType);
    129       //more than one default view for implemented interfaces are found
    130       if (temp.Count > 1)
    131         throw new InvalidOperationException("Could not determine which is the default view for type " + contentType.ToString() + ". Because more than one implemented interfaces have a default view.");
    132144      return null;
    133145    }
Note: See TracChangeset for help on using the changeset viewer.