PropertyDescriptor.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // System.ComponentModel.PropertyDescriptor.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Collections;
  11. namespace System.ComponentModel {
  12. public abstract class PropertyDescriptor : MemberDescriptor {
  13. public PropertyDescriptor (MemberDescriptor reference)
  14. : base (reference)
  15. {
  16. }
  17. public PropertyDescriptor (MemberDescriptor reference, Attribute [] attrs)
  18. : base (reference, attrs)
  19. {
  20. }
  21. public PropertyDescriptor (string name, Attribute [] attrs)
  22. : base (name, attrs)
  23. {
  24. }
  25. public abstract Type ComponentType { get; }
  26. [MonoTODO]
  27. public virtual TypeConverter Converter {
  28. get {
  29. // FIXME: Implement me.
  30. return null;
  31. }
  32. }
  33. public virtual bool IsLocalizable {
  34. get {
  35. foreach (Attribute attr in AttributeArray){
  36. if (attr is LocalizableAttribute){
  37. return ((LocalizableAttribute) attr).IsLocalizable;
  38. }
  39. }
  40. return false;
  41. }
  42. }
  43. public abstract bool IsReadOnly { get; }
  44. public abstract Type PropertyType { get; }
  45. public DesignerSerializationVisibility SerializationVisibility {
  46. get {
  47. foreach (Attribute attr in AttributeArray){
  48. if (attr is DesignerSerializationVisibilityAttribute){
  49. DesignerSerializationVisibilityAttribute a;
  50. a = (DesignerSerializationVisibilityAttribute) attr;
  51. return a.Visibility;
  52. }
  53. }
  54. //
  55. // Is this a good default if we cant find the property?
  56. //
  57. return DesignerSerializationVisibility.Hidden;
  58. }
  59. }
  60. Hashtable notifiers;
  61. public virtual void AddValueChanged (object component, EventHandler handler)
  62. {
  63. EventHandler component_notifiers;
  64. if (component == null)
  65. throw new ArgumentNullException ("component");
  66. if (handler == null)
  67. throw new ArgumentNullException ("handler");
  68. if (notifiers == null)
  69. notifiers = new Hashtable ();
  70. component_notifiers = (EventHandler) notifiers [component];
  71. if (component_notifiers != null)
  72. component_notifiers += handler;
  73. else
  74. notifiers [component] = handler;
  75. }
  76. protected virtual void OnValueChanged (object component, EventArgs e)
  77. {
  78. if (notifiers == null)
  79. return;
  80. EventHandler component_notifiers = (EventHandler) notifiers [component];
  81. if (component_notifiers == null)
  82. return;
  83. component_notifiers (component, e);
  84. }
  85. }
  86. }