- Timestamp:
- 10/30/09 11:06:10 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2444 r2456 56 56 views[viewableType].Add(t); 57 57 58 object[] attributes = t.GetCustomAttributes(typeof(DefaultView), false); 59 if (attributes != null && attributes.Length == 1) { 58 if (DefaultViewAttribute.IsDefaultView(t)) { 60 59 if (defaultViews.ContainsKey(viewableType)) 61 60 throw new ArgumentException("DefaultView for type " + viewableType + " is " + defaultViews[viewableType] + … … 74 73 IEnumerable<Type> interfaceTypes = 75 74 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") && 77 76 type.IsGenericType && !type.IsGenericTypeDefinition 78 77 select type; 79 78 80 foreach (Type interfaceType in interfaceTypes) { 81 79 foreach (Type interfaceType in interfaceTypes) { 80 yield return interfaceType.GetGenericArguments()[0]; 82 81 } 83 82 } … … 105 104 106 105 public static Type GetDefaultViewType(Type viewableType) { 106 //check if viewableType has a default view 107 107 if (defaultViews.ContainsKey(viewableType)) 108 108 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; 136 114 } 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; 137 128 } 138 129
Note: See TracChangeset
for help on using the changeset viewer.