PropertyDescriptor.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. protected PropertyDescriptor (MemberDescriptor reference)
  14. : base (reference)
  15. {
  16. }
  17. protected PropertyDescriptor (MemberDescriptor reference, Attribute [] attrs)
  18. : base (reference, attrs)
  19. {
  20. }
  21. protected PropertyDescriptor (string name, Attribute [] attrs)
  22. : base (name, attrs)
  23. {
  24. }
  25. public abstract Type ComponentType { get; }
  26. public virtual TypeConverter Converter {
  27. get {
  28. return TypeDescriptor.GetConverter (PropertyType);
  29. }
  30. }
  31. public virtual bool IsLocalizable {
  32. get {
  33. foreach (Attribute attr in AttributeArray){
  34. if (attr is LocalizableAttribute){
  35. return ((LocalizableAttribute) attr).IsLocalizable;
  36. }
  37. }
  38. return false;
  39. }
  40. }
  41. public abstract bool IsReadOnly { get; }
  42. public abstract Type PropertyType { get; }
  43. public DesignerSerializationVisibility SerializationVisibility {
  44. get {
  45. foreach (Attribute attr in AttributeArray){
  46. if (attr is DesignerSerializationVisibilityAttribute){
  47. DesignerSerializationVisibilityAttribute a;
  48. a = (DesignerSerializationVisibilityAttribute) attr;
  49. return a.Visibility;
  50. }
  51. }
  52. //
  53. // Is this a good default if we cant find the property?
  54. //
  55. return DesignerSerializationVisibility.Hidden;
  56. }
  57. }
  58. Hashtable notifiers;
  59. public virtual void AddValueChanged (object component, EventHandler handler)
  60. {
  61. EventHandler component_notifiers;
  62. if (component == null)
  63. throw new ArgumentNullException ("component");
  64. if (handler == null)
  65. throw new ArgumentNullException ("handler");
  66. if (notifiers == null)
  67. notifiers = new Hashtable ();
  68. component_notifiers = (EventHandler) notifiers [component];
  69. if (component_notifiers != null)
  70. component_notifiers += handler;
  71. else
  72. notifiers [component] = handler;
  73. }
  74. protected virtual void OnValueChanged (object component, EventArgs e)
  75. {
  76. if (notifiers == null)
  77. return;
  78. EventHandler component_notifiers = (EventHandler) notifiers [component];
  79. if (component_notifiers == null)
  80. return;
  81. component_notifiers (component, e);
  82. }
  83. public abstract object GetValue (object component);
  84. public abstract void SetValue (object component, object value);
  85. public abstract void ResetValue (object component);
  86. public abstract bool CanResetValue (object component);
  87. public abstract bool ShouldSerializeValue (object component);
  88. }
  89. }