Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/Attributes/CreatableAttribute.cs @ 12504

Last change on this file since 12504 was 12504, checked in by mkommend, 9 years ago

#2025: Changed categories for all creatables.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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;
23
24namespace HeuristicLab.Core {
25  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
26  public sealed class CreatableAttribute : Attribute {
27    #region Predefined Categories
28    public static class Categories {
29      public const string Splitter = "###";
30
31      public const string Algorithms = "Algorithms";
32      public const string PopulationBasedAlgorithms = Algorithms + Splitter + "Population Based";
33      public const string SingleSolutionAlgorithms = Algorithms + Splitter + "Single Solution";
34
35      public const string Problems = "Problems";
36      public const string CombinatorialProblems = Problems + Splitter + "Combinatorial";
37      public const string GeneticProgrammingProblems = Problems + Splitter + "Genetic Programming";
38      public const string ExternalEvaluationProblems = Problems + Splitter + "External Evaluation";
39
40      public const string DataAnalysis = "Data Analysis";
41      public const string DataAnalysisClassification = DataAnalysis + Splitter + "Classification";
42      public const string DataAnalysisRegression = DataAnalysis + Splitter + "Regression";
43      public const string DataAnalysisEnsembles = DataAnalysis + Splitter + "Ensembles";
44
45      public const string TestingAndAnalysis = "Testing & Analysis";
46      public const string TestingAndAnalysisOKB = TestingAndAnalysis + Splitter + "OKB";
47
48      public const string Scripts = "5 - Scripts";
49    }
50    #endregion
51
52    private string category;
53    public string Category {
54      get {
55        return category;
56      }
57      set {
58        if (value == null) throw new ArgumentNullException("Category", "CreataleAttribute.Category must not be null");
59        category = value;
60      }
61    }
62
63    public int Priority { get; set; }
64
65
66    public CreatableAttribute() {
67      Category = "Other Items";
68      Priority = int.MaxValue;
69    }
70    public CreatableAttribute(object category)
71      : this() {
72      Category = (string)category;
73    }
74
75    public static bool IsCreatable(Type type) {
76      object[] attribs = type.GetCustomAttributes(typeof(CreatableAttribute), false);
77      return attribs.Length > 0;
78    }
79    public static string GetCategory(Type type) {
80      object[] attribs = type.GetCustomAttributes(typeof(CreatableAttribute), false);
81      if (attribs.Length > 0) return ((CreatableAttribute)attribs[0]).Category;
82      else return null;
83    }
84
85    public static int GetPriority(Type type) {
86      var attribs = type.GetCustomAttributes(typeof(CreatableAttribute), false);
87      if (attribs.Length > 0) return ((CreatableAttribute)attribs[0]).Priority;
88      else return int.MaxValue;
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.