The Labs \ Source Viewer \ SSCLI \ System.ComponentModel \ CustomTypeDescriptor

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CustomTypeDescriptor.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.ComponentModel
  16. {
  17.    
  18.     using System;
  19.     using System.Security.Permissions;
  20.    
  21.     /// <devdoc>
  22.     /// </devdoc>
  23.     [HostProtection(SharedState = true)]
  24.     public abstract class CustomTypeDescriptor : ICustomTypeDescriptor
  25.     {
  26.         private ICustomTypeDescriptor _parent;
  27.        
  28.         /// <devdoc>
  29.         /// Creates a new CustomTypeDescriptor object. There are two versions
  30.         /// of this constructor. The version that takes no parameters simply
  31.         /// calls the version that takes a parent and passes null as the
  32.         /// parent value. If the parent is null, CustomTypeDescriptor returns
  33.         /// the defined default values for each method. If the parent is
  34.         /// non-null, CustomTypeDescriptor calls the parent's version of
  35.         /// the method.
  36.         /// </devdoc>
  37.         protected CustomTypeDescriptor()
  38.         {
  39.         }
  40.        
  41.         /// <devdoc>
  42.         /// Creates a new CustomTypeDescriptor object. There are two versions
  43.         /// of this constructor. The version that takes no parameters simply
  44.         /// calls the version that takes a parent and passes null as the
  45.         /// parent value. If the parent is null, CustomTypeDescriptor returns
  46.         /// the defined default values for each method. If the parent is
  47.         /// non-null, CustomTypeDescriptor calls the parent's version of
  48.         /// the method.
  49.         /// </devdoc>
  50.         protected CustomTypeDescriptor(ICustomTypeDescriptor parent)
  51.         {
  52.             _parent = parent;
  53.         }
  54.        
  55.         /// <devdoc>
  56.         /// The GetAttributes method returns the type-level attributes for
  57.         /// the type this custom type descriptor is providing information for.
  58.         /// You must always return a valid collection from this method.
  59.         /// </devdoc>
  60.         public virtual AttributeCollection GetAttributes()
  61.         {
  62.             if (_parent != null) {
  63.                 return _parent.GetAttributes();
  64.             }
  65.            
  66.             return AttributeCollection.Empty;
  67.         }
  68.        
  69.         /// <devdoc>
  70.         /// The GetClassName method returns the fully qualified name of the
  71.         /// class this type descriptor is representing. Returning null from
  72.         /// this method causes the TypeDescriptor object to return the
  73.         /// default class name.
  74.         /// </devdoc>
  75.         public virtual string GetClassName()
  76.         {
  77.             if (_parent != null) {
  78.                 return _parent.GetClassName();
  79.             }
  80.            
  81.             return null;
  82.         }
  83.        
  84.         /// <devdoc>
  85.         /// The GetComponentName method returns the name of the component instance
  86.         /// this type descriptor is describing.
  87.         /// </devdoc>
  88.         public virtual string GetComponentName()
  89.         {
  90.             if (_parent != null) {
  91.                 return _parent.GetComponentName();
  92.             }
  93.            
  94.             return null;
  95.         }
  96.        
  97.         /// <devdoc>
  98.         /// The GetConverter method returns a type converter for the type this type
  99.         /// descriptor is representing.
  100.         /// </devdoc>
  101.         public virtual TypeConverter GetConverter()
  102.         {
  103.             if (_parent != null) {
  104.                 return _parent.GetConverter();
  105.             }
  106.            
  107.             return new TypeConverter();
  108.         }
  109.        
  110.         /// <devdoc>
  111.         /// The GetDefaultEvent method returns the event descriptor for the default
  112.         /// event on the object this type descriptor is representing.
  113.         /// </devdoc>
  114.         public virtual EventDescriptor GetDefaultEvent()
  115.         {
  116.             if (_parent != null) {
  117.                 return _parent.GetDefaultEvent();
  118.             }
  119.            
  120.             return null;
  121.         }
  122.        
  123.         /// <devdoc>
  124.         /// The GetDefaultProperty method returns the property descriptor for the
  125.         /// default property on the object this type descriptor is representing.
  126.         /// </devdoc>
  127.         public virtual PropertyDescriptor GetDefaultProperty()
  128.         {
  129.             if (_parent != null) {
  130.                 return _parent.GetDefaultProperty();
  131.             }
  132.            
  133.             return null;
  134.         }
  135.        
  136.         /// <devdoc>
  137.         /// The GetEditor method returns an editor of the given type that is
  138.         /// to be associated with the class this type descriptor is representing.
  139.         /// </devdoc>
  140.         public virtual object GetEditor(Type editorBaseType)
  141.         {
  142.             if (_parent != null) {
  143.                 return _parent.GetEditor(editorBaseType);
  144.             }
  145.            
  146.             return null;
  147.         }
  148.        
  149.         /// <devdoc>
  150.         /// The GetEvents method returns a collection of event descriptors
  151.         /// for the object this type descriptor is representing. An optional
  152.         /// attribute array may be provided to filter the collection that is
  153.         /// returned. If no parent is provided,this will return an empty
  154.         /// event collection.
  155.         /// </devdoc>
  156.         public virtual EventDescriptorCollection GetEvents()
  157.         {
  158.             if (_parent != null) {
  159.                 return _parent.GetEvents();
  160.             }
  161.            
  162.             return EventDescriptorCollection.Empty;
  163.         }
  164.        
  165.         /// <devdoc>
  166.         /// The GetEvents method returns a collection of event descriptors
  167.         /// for the object this type descriptor is representing. An optional
  168.         /// attribute array may be provided to filter the collection that is
  169.         /// returned. If no parent is provided,this will return an empty
  170.         /// event collection.
  171.         /// </devdoc>
  172.         public virtual EventDescriptorCollection GetEvents(Attribute[] attributes)
  173.         {
  174.             if (_parent != null) {
  175.                 return _parent.GetEvents(attributes);
  176.             }
  177.            
  178.             return EventDescriptorCollection.Empty;
  179.         }
  180.        
  181.         /// <devdoc>
  182.         /// The GetProperties method returns a collection of property descriptors
  183.         /// for the object this type descriptor is representing. An optional
  184.         /// attribute array may be provided to filter the collection that is returned.
  185.         /// If no parent is provided,this will return an empty
  186.         /// property collection.
  187.         /// </devdoc>
  188.         public virtual PropertyDescriptorCollection GetProperties()
  189.         {
  190.             if (_parent != null) {
  191.                 return _parent.GetProperties();
  192.             }
  193.            
  194.             return PropertyDescriptorCollection.Empty;
  195.         }
  196.        
  197.         /// <devdoc>
  198.         /// The GetProperties method returns a collection of property descriptors
  199.         /// for the object this type descriptor is representing. An optional
  200.         /// attribute array may be provided to filter the collection that is returned.
  201.         /// If no parent is provided,this will return an empty
  202.         /// property collection.
  203.         /// </devdoc>
  204.         public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes)
  205.         {
  206.             if (_parent != null) {
  207.                 return _parent.GetProperties(attributes);
  208.             }
  209.            
  210.             return PropertyDescriptorCollection.Empty;
  211.         }
  212.        
  213.         /// <devdoc>
  214.         /// The GetPropertyOwner method returns an instance of an object that
  215.         /// owns the given property for the object this type descriptor is representing.
  216.         /// An optional attribute array may be provided to filter the collection that is
  217.         /// returned. Returning null from this method causes the TypeDescriptor object
  218.         /// to use its default type description services.
  219.         /// </devdoc>
  220.         public virtual object GetPropertyOwner(PropertyDescriptor pd)
  221.         {
  222.             if (_parent != null) {
  223.                 return _parent.GetPropertyOwner(pd);
  224.             }
  225.            
  226.             return null;
  227.         }
  228.     }
  229. }

Developer Fusion