Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DisplayAttribute.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Linq;
5 using System.Reflection;
6 using SiliconStudio.Core.Reflection;
7 
8 namespace SiliconStudio.Paradox.Engine
9 {
10  public class DisplayAttribute : Attribute
11  {
12  private readonly int order;
13 
14  private readonly string name;
15 
16  private readonly string category;
17 
18  private readonly string description;
19 
20  public DisplayAttribute(int order , string name = null, string category = null, string description = null)
21  {
22  this.order = order;
23  this.name = name;
24  this.category = category;
25  this.description = description;
26  }
27 
28  public DisplayAttribute(string name = null, string category = null, string description = null) : this(0, name, category, description)
29  {
30  }
31 
32  public int Order
33  {
34  get
35  {
36  return order;
37  }
38  }
39 
40  public string Name
41  {
42  get
43  {
44  return name;
45  }
46  }
47 
48  public string Category
49  {
50  get
51  {
52  return category;
53  }
54  }
55 
56  public string Description
57  {
58  get
59  {
60  return description;
61  }
62  }
63 
64  public static bool IsDisplayable(object obj)
65  {
66  return IsDisplayable(obj.GetType());
67  }
68 
69  public static bool IsDisplayable(Type type)
70  {
71  return type.GetTypeInfo().GetCustomAttributes(typeof(DisplayAttribute), true).GetEnumerator().MoveNext();
72  }
73 
74  public static DisplayAttribute GetDisplay(Type type)
75  {
76  var attributes = type.GetTypeInfo().GetCustomAttributes(typeof(DisplayAttribute), true);
77  return attributes.FirstOrDefault() as DisplayAttribute;
78  }
79 
80  public static DisplayAttribute GetDisplay(MemberInfo memberInfo)
81  {
82  var attributes = memberInfo.GetCustomAttributes(typeof(DisplayAttribute), true);
83  return attributes.FirstOrDefault() as DisplayAttribute;
84  }
85  }
86 }
DisplayAttribute(int order, string name=null, string category=null, string description=null)
DisplayAttribute(string name=null, string category=null, string description=null)
static DisplayAttribute GetDisplay(MemberInfo memberInfo)
static DisplayAttribute GetDisplay(Type type)