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

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

Developer Fusion