Changeset 2437 for branches/Mainform refactoring/HeuristicLab.MainForm
- Timestamp:
- 10/18/09 01:08:12 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2433 r2437 84 84 85 85 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 } 94 91 return viewsForType.Distinct(); 95 92 } … … 100 97 101 98 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]; 105 119 } 106 120 … … 110 124 return null; 111 125 else 112 return (IView<T>) 126 return (IView<T>)Activator.CreateInstance(t); 113 127 } 114 128 }
Note: See TracChangeset
for help on using the changeset viewer.