3250a8a07b83bb5ba33eb9554b35ed1110c2d63a
[mono.git] / mcs / class / System / System.ComponentModel / MemberDescriptor.cs
1 //
2 // System.ComponentModel.MemberDescriptor.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 namespace System.ComponentModel {
11
12         public abstract class MemberDescriptor {
13                 string name;
14                 Attribute [] attrs;
15                 AttributeCollection attrCollection;
16                 
17                 protected MemberDescriptor (string name, Attribute [] attrs)
18                 {
19                         this.name = name;
20                         this.attrs = attrs;
21                 }
22
23                 protected MemberDescriptor (MemberDescriptor reference, Attribute [] attrs)
24                 {
25                         name = reference.name;
26                         this.attrs = attrs;
27                 }
28
29                 protected MemberDescriptor (string name)
30                 {
31                         this.name = name;
32                 }
33
34                 protected MemberDescriptor (MemberDescriptor reference)
35                 {
36                         name = reference.name;
37                         attrs = reference.attrs;
38                 }
39
40                 protected virtual Attribute [] AttributeArray {
41                         get {
42                                 return attrs;
43                         }
44
45                         set {
46                                 attrs = value;
47                         }
48                 }
49
50                 public virtual AttributeCollection Attributes
51                 {
52                         get {
53                                 if (attrCollection == null)
54                                         attrCollection = new AttributeCollection (attrs);
55                                 return attrCollection;
56                         }
57                 }
58                         
59                 public virtual string Category {
60                         get {
61                                 return ((CategoryAttribute) Attributes [typeof (CategoryAttribute)]).Category;
62                         }
63                 }
64
65                 public virtual string Description {
66                         get {
67                                 foreach (Attribute attr in attrs){
68                                         if (attr is DescriptionAttribute)
69                                                 return ((DescriptionAttribute) attr).Description;
70                                 }
71
72                                 return "";
73                         }
74                 }
75
76                 public virtual bool DesignTimeOnly {
77                         get {
78                                 foreach (Attribute attr in attrs){
79                                         if (attr is DesignOnlyAttribute)
80                                                 return ((DesignOnlyAttribute) attr).IsDesignOnly;
81                                 }
82
83                                 return false;
84                         }
85                 }
86
87                 //
88                 // FIXME: Is there any difference between DisplayName and Name?
89                 //
90                 [MonoTODO ("Does this diff from Name ?")]
91                 public virtual string DisplayName {
92                         get {
93                                 return name;
94                         }
95                 }
96
97                 public virtual string Name {
98                         get {
99                                 return name;
100                         }
101                 }
102
103                 public virtual bool IsBrowsable {
104                         get {
105                                 foreach (Attribute attr in attrs){
106                                         if (attr is BrowsableAttribute)
107                                                 return ((BrowsableAttribute) attr).Browsable;
108                                 }
109
110                                 return false;
111                         }
112                 }
113
114                 protected virtual int NameHashCode {
115                         get {
116                                 return name.GetHashCode ();
117                         }
118                 }
119         }
120 }