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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="UInt16Converter.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.Diagnostics;
  21.     using System.Globalization;
  22.     using System.Runtime.InteropServices;
  23.     using System.Runtime.Remoting;
  24.     using System.Runtime.Serialization.Formatters;
  25.     using System.Security.Permissions;
  26.    
  27.     /// <devdoc>
  28.     /// <para>Provides a type converter to convert 16-bit unsigned integer objects to and
  29.     /// from various other representations.</para>
  30.     /// </devdoc>
  31.     [HostProtection(SharedState = true)]
  32.     public class UInt16Converter : BaseNumberConverter
  33.     {
  34.        
  35.         /// <devdoc>
  36.         /// The Type this converter is targeting (e.g. Int16, UInt32, etc.)
  37.         /// </devdoc>
  38.         internal override Type TargetType {
  39.             get { return typeof(UInt16); }
  40.         }
  41.        
  42.         /// <devdoc>
  43.         /// Convert the given value to a string using the given radix
  44.         /// </devdoc>
  45.         internal override object FromString(string value, int radix)
  46.         {
  47.             return Convert.ToUInt16(value, radix);
  48.         }
  49.        
  50.         /// <devdoc>
  51.         /// Convert the given value to a string using the given formatInfo
  52.         /// </devdoc>
  53.         internal override object FromString(string value, NumberFormatInfo formatInfo)
  54.         {
  55.             return UInt16.Parse(value, NumberStyles.Integer, formatInfo);
  56.         }
  57.        
  58.        
  59.         /// <devdoc>
  60.         /// Convert the given value to a string using the given CultureInfo
  61.         /// </devdoc>
  62.         internal override object FromString(string value, CultureInfo culture)
  63.         {
  64.             return UInt16.Parse(value, culture);
  65.         }
  66.        
  67.         /// <devdoc>
  68.         /// Convert the given value from a string using the given formatInfo
  69.         /// </devdoc>
  70.         internal override string ToString(object value, NumberFormatInfo formatInfo)
  71.         {
  72.             return ((UInt16)value).ToString("G", formatInfo);
  73.         }
  74.        
  75.     }
  76. }

Developer Fusion