MemberDescriptor.cs 2.1 KB

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