Jypeli  9
The simple game programming library
AdvBrowsableAttribute.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17  * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #endregion
23 using System;
24 using System.Collections.Generic;
25 using System.ComponentModel;
26 using System.Reflection;
27 
29 {
30 
31  [global::System.AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
32  public sealed class AdvBrowsableAttribute : Attribute
33  {
34  string name;
35  public AdvBrowsableAttribute() : this(null) { }
36  public AdvBrowsableAttribute(string name)
37  {
38  this.name = name;
39  }
40  public string Name
41  {
42  get { return name; }
43  }
44 #if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
45  public static PropertyDescriptorCollection GetDispMembers(Type t)
46  {
47  string[] order = AdvBrowsableOrderAttribute.GetOrder(t);
48  List<PropertyDescriptor> rv = new List<PropertyDescriptor>();
49  object[] atts;
50  foreach (PropertyInfo info in t.GetProperties())
51  {
52  atts = info.GetCustomAttributes(typeof(AdvBrowsableAttribute), true);
53  if (atts.Length > 0)
54  {
56  AdvPropertyDescriptor descriptor;
57  if (att.Name != null)
58  {
59  descriptor = new AdvPropertyDescriptor(att.Name, info);
60  }
61  else
62  {
63  descriptor = new AdvPropertyDescriptor(info);
64  }
65  atts = info.GetCustomAttributes(typeof(DescriptionAttribute), true);
66  if (atts.Length > 0)
67  {
68  DescriptionAttribute att2 = (DescriptionAttribute)atts[0];
69  descriptor.SetDescription(att2.Description);
70  }
71  rv.Add(descriptor);
72  }
73  }
74  foreach (FieldInfo info in t.GetFields())
75  {
76  atts = info.GetCustomAttributes(typeof(AdvBrowsableAttribute), true);
77  if (atts.Length > 0)
78  {
80  AdvPropertyDescriptor descriptor;
81  if (att.Name != null)
82  {
83  descriptor= new AdvPropertyDescriptor(att.Name, info);
84  }
85  else
86  {
87  descriptor= new AdvPropertyDescriptor(info);
88  }
89  atts = info.GetCustomAttributes(typeof(DescriptionAttribute), true);
90  if (atts.Length > 0)
91  {
92  DescriptionAttribute att2 = (DescriptionAttribute)atts[0];
93  descriptor.SetDescription(att2.Description);
94  }
95  rv.Add(descriptor);
96  }
97  }
98  if (rv.Count == 0)
99  {
100  return null;
101  }
102  if (order != null)
103  {
104  return new PropertyDescriptorCollection(rv.ToArray()).Sort(order);
105  }
106  return new PropertyDescriptorCollection(rv.ToArray());
107  }
108 #endif
109  }
110 
111 }
AdvanceMath.Design.AdvBrowsableAttribute
Definition: AdvBrowsableAttribute.cs:33
AdvanceMath.Design.AdvPropertyDescriptor.SetDescription
void SetDescription(string value)
Definition: AdvPropertyDescriptor.cs:128
AdvanceMath.Design.AdvBrowsableAttribute.name
string name
Definition: AdvBrowsableAttribute.cs:34
AdvanceMath.Design.AdvPropertyDescriptor
Definition: AdvPropertyDescriptor.cs:34
AdvanceMath.Design.AdvBrowsableAttribute.AdvBrowsableAttribute
AdvBrowsableAttribute(string name)
Definition: AdvBrowsableAttribute.cs:36
AdvanceMath.Design.AdvBrowsableAttribute.GetDispMembers
static PropertyDescriptorCollection GetDispMembers(Type t)
Definition: AdvBrowsableAttribute.cs:45
AdvanceMath.Design.AdvBrowsableOrderAttribute
Definition: AdvBrowsableOrderAttribute.cs:29
AdvanceMath.Design.AdvBrowsableOrderAttribute.GetOrder
static string[] GetOrder(Type type)
Definition: AdvBrowsableOrderAttribute.cs:46
System
Definition: CFFauxAttributes.cs:29
AdvanceMath.Design.AdvBrowsableAttribute.AdvBrowsableAttribute
AdvBrowsableAttribute()
Definition: AdvBrowsableAttribute.cs:35
AdvanceMath.Design
Definition: AdvBrowsableAttribute.cs:29
AdvanceMath.Design.AdvBrowsableAttribute.Name
string Name
Definition: AdvBrowsableAttribute.cs:41