Changeset 2837 for trunk/sources/HeuristicLab.MainForm/3.2/ViewAttribute.cs
- Timestamp:
- 02/19/10 11:45:51 (14 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm/3.2/ViewAttribute.cs
r2835 r2837 27 27 28 28 namespace HeuristicLab.MainForm { 29 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]30 public sealed class ContentAttribute : Attribute {31 public ContentAttribute(Type contentType) {32 this. contentType = contentType;29 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 30 public sealed class ViewAttribute : Attribute { 31 public ViewAttribute(string name) { 32 this.name = name; 33 33 } 34 34 35 public ContentAttribute(Type contentType, bool isDefaultView) 36 : this(contentType) { 37 this.isDefaultView = isDefaultView; 35 private string name; 36 public string Name { 37 get { return this.name; } 38 set { this.name = value; } 38 39 } 39 40 40 private bool isDefaultView; 41 public bool IsDefaultView { 42 get { return this.isDefaultView; } 43 set { this.isDefaultView = value; } 44 } 45 46 private Type contentType; 47 public Type ContentType { 48 get { return this.contentType; } 49 } 50 51 public static bool HasContentAttribute(MemberInfo viewType) { 52 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 41 public static bool HasViewAttribute(MemberInfo viewType) { 42 ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false); 53 43 return attributes.Length != 0; 54 44 } 55 45 56 public static bool CanViewType(MemberInfo viewType, Type content) { 57 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 58 return attributes.Any(a => content.IsAssignableTo(a.contentType)); 59 } 60 61 internal static IEnumerable<Type> GetDefaultViewableTypes(Type viewType) { 62 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 63 return from a in attributes 64 where a.isDefaultView 65 select a.contentType; 66 } 67 68 internal static IEnumerable<Type> GetViewableTypes(Type viewType) { 69 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 70 return from a in attributes 71 select a.contentType; 46 public static string GetViewName(MemberInfo viewType) { 47 ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false); 48 if (attributes.Length == 1) 49 return attributes[0].Name; 50 return viewType.Name; 72 51 } 73 52 }
Note: See TracChangeset
for help on using the changeset viewer.