| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // System.ComponentModel.PropertyDescriptor.cs
- //
- // Author:
- // Miguel de Icaza ([email protected])
- // Andreas Nahr ([email protected])
- //
- // (C) Ximian, Inc. http://www.ximian.com
- // (C) 2003 Andreas Nahr
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections;
- using System.Reflection;
- using System.Runtime.InteropServices;
- namespace System.ComponentModel
- {
- [ComVisible (true)]
- public abstract class PropertyDescriptor : MemberDescriptor
- {
- TypeConverter converter;
- protected PropertyDescriptor (MemberDescriptor reference)
- : base (reference)
- {
- }
- protected PropertyDescriptor (MemberDescriptor reference, Attribute [] attrs)
- : base (reference, attrs)
- {
- }
- protected PropertyDescriptor (string name, Attribute [] attrs)
- : base (name, attrs)
- {
- }
- public abstract Type ComponentType { get; }
- public virtual TypeConverter Converter {
- get {
- if (converter == null) {
- TypeConverterAttribute at = (TypeConverterAttribute) Attributes [typeof(TypeConverterAttribute)];
- if (at == null || at == TypeConverterAttribute.Default)
- converter = TypeDescriptor.GetConverter (PropertyType);
- else {
- Type t = Type.GetType (at.ConverterTypeName);
- if (t == null) {
- converter = TypeDescriptor.GetConverter (PropertyType);
- }
- else {
- ConstructorInfo ci = t.GetConstructor (new Type[] { typeof(Type) });
- if (ci != null)
- converter = (TypeConverter) ci.Invoke (new object[] { PropertyType });
- else
- converter = (TypeConverter) Activator.CreateInstance (t);
- }
- }
- }
- return converter;
- }
- }
- public virtual bool IsLocalizable {
- get {
- foreach (Attribute attr in AttributeArray){
- if (attr is LocalizableAttribute)
- return ((LocalizableAttribute) attr).IsLocalizable;
- }
- return false;
- }
- }
- public abstract bool IsReadOnly { get; }
- public abstract Type PropertyType { get; }
- #if NET_2_0
- public virtual bool SupportsChangeEvents {
- get { return false; }
- }
- #endif
- public DesignerSerializationVisibility SerializationVisibility {
- get {
- foreach (Attribute attr in AttributeArray) {
- if (attr is DesignerSerializationVisibilityAttribute){
- DesignerSerializationVisibilityAttribute a;
- a = (DesignerSerializationVisibilityAttribute) attr;
- return a.Visibility;
- }
- }
- return DesignerSerializationVisibility.Visible;
- }
- }
- Hashtable notifiers;
- public virtual void AddValueChanged (object component, EventHandler handler)
- {
- EventHandler component_notifiers;
- if (component == null)
- throw new ArgumentNullException ("component");
- if (handler == null)
- throw new ArgumentNullException ("handler");
- if (notifiers == null)
- notifiers = new Hashtable ();
- component_notifiers = (EventHandler) notifiers [component];
- if (component_notifiers != null)
- component_notifiers += handler;
- else
- notifiers [component] = handler;
- }
- public virtual void RemoveValueChanged (object component, System.EventHandler handler)
- {
- EventHandler component_notifiers;
- if (component == null)
- throw new ArgumentNullException ("component");
- if (handler == null)
- throw new ArgumentNullException ("handler");
- if (notifiers == null) return;
- component_notifiers = (EventHandler) notifiers [component];
- component_notifiers -= handler;
-
- if (component_notifiers == null)
- notifiers.Remove (component);
- else
- notifiers [component] = handler;
- }
- #if NET_2_0
- [MonoNotSupported ("")]
- protected override void FillAttributes (IList attributeList)
- {
- base.FillAttributes (attributeList);
- }
- [MonoNotSupported ("")]
- protected override Object GetInvocationTarget (Type type, object instance)
- {
- return base.GetInvocationTarget (type, instance);
- }
- [MonoNotSupported("")]
- protected internal EventHandler GetValueChangedHandler (object component)
- {
- throw new NotImplementedException ();
- }
- #endif
- protected virtual void OnValueChanged (object component, EventArgs e)
- {
- if (notifiers == null)
- return;
- EventHandler component_notifiers = (EventHandler) notifiers [component];
- if (component_notifiers == null)
- return;
- component_notifiers (component, e);
- }
- public abstract object GetValue (object component);
- public abstract void SetValue (object component, object value);
- public abstract void ResetValue (object component);
- public abstract bool CanResetValue (object component);
- public abstract bool ShouldSerializeValue (object component);
- protected object CreateInstance(System.Type type)
- {
- return Assembly.GetExecutingAssembly ().CreateInstance (type.Name);
- }
- public override bool Equals(object obj)
- {
- if (!base.Equals (obj)) return false;
- PropertyDescriptor other = obj as PropertyDescriptor;
- if (other == null) return false;
- return other.PropertyType == PropertyType;
- }
- public PropertyDescriptorCollection GetChildProperties()
- {
- return GetChildProperties (null, null);
- }
- public PropertyDescriptorCollection GetChildProperties(object instance)
- {
- return GetChildProperties (instance, null);
- }
- public PropertyDescriptorCollection GetChildProperties(Attribute[] filter)
- {
- return GetChildProperties (null, filter);
- }
- public override int GetHashCode()
- {
- return base.GetHashCode ();
- }
- public virtual PropertyDescriptorCollection GetChildProperties (object instance, Attribute[] filter)
- {
- return TypeDescriptor.GetProperties (instance, filter);
- }
- public virtual object GetEditor(Type editorBaseType)
- {
- return TypeDescriptor.GetEditor (PropertyType, editorBaseType);
- }
- protected Type GetTypeFromName(string typeName)
- {
- return Type.GetType (typeName);
- }
- }
- }
|