Changeset 2761 for trunk/sources/HeuristicLab.MainForm
- Timestamp:
- 02/08/10 15:35:20 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm/3.2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm/3.2/ContentAttribute.cs
r2724 r2761 24 24 using System.Linq; 25 25 using System.Text; 26 using System.Reflection; 26 27 27 28 namespace HeuristicLab.MainForm { 28 29 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] 29 public class ContentAttribute : Attribute { 30 private Type type; 31 public ContentAttribute(Type type) { 32 this.type = type; 30 public sealed class ContentAttribute : Attribute { 31 public ContentAttribute(Type contentType) { 32 this.contentType = contentType; 33 33 } 34 34 35 public ContentAttribute(Type type, bool isDefaultView)36 : this( type) {35 public ContentAttribute(Type contentType, bool isDefaultView) 36 : this(contentType) { 37 37 this.isDefaultView = isDefaultView; 38 38 } … … 44 44 } 45 45 46 public static bool HasContentAttribute(Type viewType) { 46 private Type contentType; 47 public Type ContentType { 48 get { return this.contentType; } 49 } 50 51 public static bool HasContentAttribute(MemberInfo viewType) { 47 52 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 48 53 return attributes.Length != 0; 49 54 } 50 55 51 public static bool CanViewType( TypeviewType, Type content) {56 public static bool CanViewType(MemberInfo viewType, Type content) { 52 57 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 53 return attributes.Any(a => content.IsAssignableTo(a. type));58 return attributes.Any(a => content.IsAssignableTo(a.contentType)); 54 59 } 55 60 … … 58 63 return from a in attributes 59 64 where a.isDefaultView 60 select a. type;65 select a.contentType; 61 66 } 62 67 … … 64 69 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 65 70 return from a in attributes 66 select a. type;71 select a.contentType; 67 72 } 68 73 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IPositionableUserInterfaceItem.cs
r2696 r2761 26 26 27 27 namespace HeuristicLab.MainForm { 28 public interface IPositionableUserInterfaceItem : IUserInterfaceItem {28 public interface IPositionableUserInterfaceItem : IUserInterfaceItem { 29 29 int Position { get; } 30 30 IEnumerable<string> Structure { get; } -
trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2726 r2761 28 28 29 29 namespace HeuristicLab.MainForm { 30 class StringDict<T> : Dictionary<string, T> {31 }32 30 public static class MainFormManager { 33 31 private static object locker; … … 38 36 static MainFormManager() { 39 37 locker = new object(); 38 mainform = null; 40 39 views = new HashSet<Type>(); 41 40 defaultViews = new Dictionary<Type, Type>(); 42 41 } 43 42 44 public static void RegisterMainForm(IMainForm main form) {43 public static void RegisterMainForm(IMainForm mainForm) { 45 44 lock (locker) { 46 45 if (MainFormManager.mainform != null) 47 46 throw new ArgumentException("A mainform was already associated with the mainform manager."); 48 if (main form == null)47 if (mainForm == null) 49 48 throw new ArgumentException("Could not associate null as a mainform in the mainform manager."); 50 49 51 MainFormManager.mainform = main form;50 MainFormManager.mainform = mainForm; 52 51 IEnumerable<Type> types = 53 52 from t in ApplicationManager.Manager.GetTypes(typeof(IView)) … … 86 85 } 87 86 88 public static bool ViewCanViewObject(IView view, object o) {89 return ContentAttribute.CanViewType(view.GetType(), o.GetType());87 public static bool ViewCanViewObject(IView view, object content) { 88 return ContentAttribute.CanViewType(view.GetType(), content.GetType()); 90 89 } 91 90 … … 113 112 //more than one default view for implemented interfaces are found 114 113 if (temp.Count > 1) 115 throw new Exception("Could not determine which is the default view for type " + contentType.ToString() + ". Because more than one implemented interfaces have a default view.");114 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."); 116 115 return null; 117 116 } 118 117 119 public static IView CreateDefaultView(object objectToView) {120 Type t = GetDefaultViewType( objectToView.GetType());118 public static IView CreateDefaultView(object content) { 119 Type t = GetDefaultViewType(content.GetType()); 121 120 if (t == null) 122 121 return null; 123 122 124 return (IView)Activator.CreateInstance(t, objectToView);123 return (IView)Activator.CreateInstance(t, content); 125 124 } 126 125 … … 134 133 } 135 134 136 public static IView CreateView(Type viewType, object objectToView) {135 public static IView CreateView(Type viewType, object content) { 137 136 if (!typeof(IView).IsAssignableFrom(viewType)) 138 137 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView."); … … 140 139 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is a generic type definition."); 141 140 142 return (IView)Activator.CreateInstance(viewType, objectToView);141 return (IView)Activator.CreateInstance(viewType, content); 143 142 } 144 143 -
trunk/sources/HeuristicLab.MainForm/3.2/TypeExtension.cs
r2724 r2761 78 78 return true; 79 79 } 80 81 internal static Type[] ExtractGenericTypeArguments(this Type type, Type other) {82 Type[] types = new Type[0];83 return types;84 }85 80 } 86 81 }
Note: See TracChangeset
for help on using the changeset viewer.