Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/19/10 11:45:51 (14 years ago)
Author:
mkommend
Message:

added ViewAttribute and adapted ViewContextMenuStrip (ticket #857)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm/3.2/ViewAttribute.cs

    r2835 r2837  
    2727
    2828namespace 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;
    3333    }
    3434
    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; }
    3839    }
    3940
    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);
    5343      return attributes.Length != 0;
    5444    }
    5545
    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;
    7251    }
    7352  }
Note: See TracChangeset for help on using the changeset viewer.