Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.MainForm/3.3/ViewAttribute.cs @ 16666

Last change on this file since 16666 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Reflection;
24
25namespace HeuristicLab.MainForm {
26  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
27  public sealed class ViewAttribute : Attribute {
28    public ViewAttribute(string name) {
29      this.name = name;
30      this.helpResourcePath = string.Empty;
31    }
32
33    public ViewAttribute(string name, string helpResourcePath) {
34      this.name = name;
35      this.helpResourcePath = helpResourcePath;
36    }
37
38    private string name;
39    public string Name {
40      get { return this.name; }
41      set { this.name = value; }
42    }
43
44    private string helpResourcePath;
45    public string HelpResourcePath {
46      get { return this.helpResourcePath; }
47      set { this.helpResourcePath = value; }
48    }
49
50    public static bool HasViewAttribute(MemberInfo viewType) {
51      ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false);
52      return attributes.Length != 0;
53    }
54
55    public static string GetViewName(MemberInfo viewType) {
56      ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false);
57      if (attributes.Length == 1)
58        return attributes[0].Name;
59      return viewType.Name;
60    }
61
62    public static string GetHelpResourcePath(MemberInfo viewType) {
63      ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false);
64      if (attributes.Length == 1)
65        return attributes[0].helpResourcePath;
66      return string.Empty;
67    }
68
69    public static bool HasHelpResourcePath(MemberInfo viewType) {
70      ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false);
71      if (attributes.Length == 1)
72        return attributes[0].helpResourcePath != string.Empty;
73      return false;
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.