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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CollectionConverter.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. /*
  16. */
  17. namespace System.ComponentModel
  18. {
  19.     using Microsoft.Win32;
  20.     using System.Collections;
  21.     using System.ComponentModel;
  22.     using System.Diagnostics;
  23.     using System.Globalization;
  24.     using System.Runtime.Serialization.Formatters;
  25.     using System.Runtime.Remoting;
  26.     using System.Runtime.InteropServices;
  27.     using System.Security.Permissions;
  28.    
  29.     /// <devdoc>
  30.     /// <para>Provides a type converter to convert
  31.     /// collection objects to and from various other representations.</para>
  32.     /// </devdoc>
  33.     [HostProtection(SharedState = true)]
  34.     public class CollectionConverter : TypeConverter
  35.     {
  36.        
  37.         /// <devdoc>
  38.         /// <para>Converts the given
  39.         /// value object to the
  40.         /// specified destination type.</para>
  41.         /// </devdoc>
  42.         public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
  43.         {
  44.             if (destinationType == null) {
  45.                 throw new ArgumentNullException("destinationType");
  46.             }
  47.            
  48.             if (destinationType == typeof(string)) {
  49.                 if (value is ICollection) {
  50.                     return SR.GetString(SR.CollectionConverterText);
  51.                 }
  52.             }
  53.            
  54.             return base.ConvertTo(context, culture, value, destinationType);
  55.         }
  56.        
  57.         /// <devdoc>
  58.         /// <para>Gets a collection of properties for
  59.         /// the type of array specified by the value parameter using the specified context and
  60.         /// attributes.</para>
  61.         /// </devdoc>
  62.         public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
  63.         {
  64.             //return new PropertyDescriptorCollection(null);
  65.             return null;
  66.         }
  67.        
  68.         /// <devdoc>
  69.         /// <para>Gets a value indicating whether this object
  70.         /// supports properties.</para>
  71.         /// </devdoc>
  72.         public override bool GetPropertiesSupported(ITypeDescriptorContext context)
  73.         {
  74.             return false;
  75.         }
  76.        
  77.        
  78.     }
  79. }

Developer Fusion