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

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

Developer Fusion