Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/08/12 15:17:58 (13 years ago)
Author:
mkommend
Message:

#1794: Implemented analysis of interface hierarchies in MainFormManager for default view discovery.

File:
1 edited

Legend:

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

    r7259 r7587  
    118118        }
    119119
    120         //check interfaces
    121         IEnumerable<Type> nonInheritedInterfaces = type.GetInterfaces().Where(i => !i.IsAssignableFrom(type.BaseType));
    122         List<Type> defaultViewList = new List<Type>();
    123         foreach (Type defaultContentType in defaultViews.Keys) {
    124           if (nonInheritedInterfaces.Contains(defaultContentType) || nonInheritedInterfaces.Any(i => i.CheckGenericTypes(defaultContentType)))
    125             defaultViewList.Add(defaultViews[defaultContentType]);
    126         }
    127 
    128         //return only most spefic view as default view
    129         foreach (Type viewType in defaultViewList.ToList()) {
    130           if (defaultViewList.Any(t => t.IsSubclassOf(viewType)))
    131             defaultViewList.Remove(viewType);
    132         }
    133 
    134         if (defaultViewList.Count == 1)
    135           return TransformGenericTypeDefinition(defaultViewList[0], contentType);
    136         else if (defaultViewList.Count > 1)
    137           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.");
     120        //check interfaces hierarchy of implemented and not inherited interfaces
     121        var nonInheritedInterfaces = type.GetInterfaces().Where(i => !i.IsAssignableFrom(type.BaseType));
     122        var interfaces = new HashSet<Type>(nonInheritedInterfaces);
     123
     124        while (interfaces.Any()) {
     125          interfaces.RemoveWhere(i => interfaces.Any(x => x.GetInterfaces().Contains(i)));
     126
     127          List<Type> defaultViewList = (from defaultContentType in defaultViews.Keys
     128                                        where interfaces.Contains(defaultContentType) ||
     129                                              interfaces.Any(i => i.CheckGenericTypes(defaultContentType))
     130                                        select defaultViews[defaultContentType]).ToList();
     131
     132          //return only most spefic view as default view
     133          foreach (Type viewType in defaultViewList.ToList()) {
     134            if (defaultViewList.Any(t => t.IsSubclassOf(viewType)))
     135              defaultViewList.Remove(viewType);
     136          }
     137
     138          if (defaultViewList.Count == 1)
     139            return TransformGenericTypeDefinition(defaultViewList[0], contentType);
     140          else if (defaultViewList.Count > 1)
     141            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.");
     142
     143          interfaces = new HashSet<Type>(interfaces.SelectMany(i => i.GetInterfaces()));
     144        }
    138145
    139146        type = type.BaseType;
Note: See TracChangeset for help on using the changeset viewer.