PropertyDescriptor.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // System.ComponentModel.PropertyDescriptor.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Ximian, Inc. http://www.ximian.com
  9. // (C) 2003 Andreas Nahr
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. namespace System.ComponentModel
  16. {
  17. [ComVisible (true)]
  18. public abstract class PropertyDescriptor : MemberDescriptor
  19. {
  20. protected PropertyDescriptor (MemberDescriptor reference)
  21. : base (reference)
  22. {
  23. }
  24. protected PropertyDescriptor (MemberDescriptor reference, Attribute [] attrs)
  25. : base (reference, attrs)
  26. {
  27. }
  28. protected PropertyDescriptor (string name, Attribute [] attrs)
  29. : base (name, attrs)
  30. {
  31. }
  32. public abstract Type ComponentType { get; }
  33. public virtual TypeConverter Converter {
  34. get { return TypeDescriptor.GetConverter (PropertyType); }
  35. }
  36. public virtual bool IsLocalizable {
  37. get {
  38. foreach (Attribute attr in AttributeArray){
  39. if (attr is LocalizableAttribute)
  40. return ((LocalizableAttribute) attr).IsLocalizable;
  41. }
  42. return false;
  43. }
  44. }
  45. public abstract bool IsReadOnly { get; }
  46. public abstract Type PropertyType { get; }
  47. public DesignerSerializationVisibility SerializationVisibility {
  48. get {
  49. foreach (Attribute attr in AttributeArray) {
  50. if (attr is DesignerSerializationVisibilityAttribute){
  51. DesignerSerializationVisibilityAttribute a;
  52. a = (DesignerSerializationVisibilityAttribute) attr;
  53. return a.Visibility;
  54. }
  55. }
  56. //
  57. // Is this a good default if we cant find the property?
  58. //
  59. return DesignerSerializationVisibility.Hidden;
  60. }
  61. }
  62. Hashtable notifiers;
  63. public virtual void AddValueChanged (object component, EventHandler handler)
  64. {
  65. EventHandler component_notifiers;
  66. if (component == null)
  67. throw new ArgumentNullException ("component");
  68. if (handler == null)
  69. throw new ArgumentNullException ("handler");
  70. if (notifiers == null)
  71. notifiers = new Hashtable ();
  72. component_notifiers = (EventHandler) notifiers [component];
  73. if (component_notifiers != null)
  74. component_notifiers += handler;
  75. else
  76. notifiers [component] = handler;
  77. }
  78. [MonoTODO]
  79. public virtual void RemoveValueChanged(object component, System.EventHandler handler)
  80. {
  81. throw new NotImplementedException();
  82. }
  83. protected virtual void OnValueChanged (object component, EventArgs e)
  84. {
  85. if (notifiers == null)
  86. return;
  87. EventHandler component_notifiers = (EventHandler) notifiers [component];
  88. if (component_notifiers == null)
  89. return;
  90. component_notifiers (component, e);
  91. }
  92. public abstract object GetValue (object component);
  93. public abstract void SetValue (object component, object value);
  94. public abstract void ResetValue (object component);
  95. public abstract bool CanResetValue (object component);
  96. public abstract bool ShouldSerializeValue (object component);
  97. protected object CreateInstance(System.Type type)
  98. {
  99. return Assembly.GetExecutingAssembly ().CreateInstance (type.Name);
  100. }
  101. [MonoTODO ("Not correctly implemented")]
  102. public override bool Equals(object obj)
  103. {
  104. if (!(obj is PropertyDescriptor))
  105. return false;
  106. if (obj == this)
  107. return true;
  108. return (((PropertyDescriptor) obj).AttributeArray == this.AttributeArray) &&
  109. (((PropertyDescriptor) obj).Attributes == this.Attributes) &&
  110. (((PropertyDescriptor) obj).DisplayName == this.DisplayName) &&
  111. (((PropertyDescriptor) obj).Name == this.Name);
  112. }
  113. public PropertyDescriptorCollection GetChildProperties()
  114. {
  115. return GetChildProperties (null, null);
  116. }
  117. public PropertyDescriptorCollection GetChildProperties(object instance)
  118. {
  119. return GetChildProperties (instance, null);
  120. }
  121. public PropertyDescriptorCollection GetChildProperties(Attribute[] filter)
  122. {
  123. return GetChildProperties (null, filter);
  124. }
  125. [MonoTODO ("Incorrect implementation")]
  126. public override int GetHashCode()
  127. {
  128. return Name.GetHashCode ();
  129. }
  130. [MonoTODO]
  131. public virtual PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter)
  132. {
  133. throw new NotImplementedException();
  134. }
  135. [MonoTODO]
  136. public virtual object GetEditor(Type editorBaseType)
  137. {
  138. throw new NotImplementedException();
  139. }
  140. protected Type GetTypeFromName(string typeName)
  141. {
  142. return Type.GetType (typeName);
  143. }
  144. }
  145. }