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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SingleConverter.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.    
  28.     /// <devdoc>
  29.     /// <para> Provides a type
  30.     /// converter to convert single-precision, floating point number objects to and from various other
  31.     /// representations.</para>
  32.     /// </devdoc>
  33.     [HostProtection(SharedState = true)]
  34.     public class SingleConverter : BaseNumberConverter
  35.     {
  36.        
  37.        
  38.         /// <devdoc>
  39.         /// Determines whether this editor will attempt to convert hex (0x or #) strings
  40.         /// </devdoc>
  41.         internal override bool AllowHex {
  42.             get { return false; }
  43.         }
  44.        
  45.         /// <devdoc>
  46.         /// The Type this converter is targeting (e.g. Int16, UInt32, etc.)
  47.         /// </devdoc>
  48.         internal override Type TargetType {
  49.             get { return typeof(float); }
  50.         }
  51.        
  52.         /// <devdoc>
  53.         /// Convert the given value to a string using the given radix
  54.         /// </devdoc>
  55.         internal override object FromString(string value, int radix)
  56.         {
  57.             return Convert.ToSingle(value, CultureInfo.CurrentCulture);
  58.         }
  59.        
  60.         /// <devdoc>
  61.         /// Convert the given value to a string using the given formatInfo
  62.         /// </devdoc>
  63.         internal override object FromString(string value, NumberFormatInfo formatInfo)
  64.         {
  65.             return Single.Parse(value, NumberStyles.Float, formatInfo);
  66.         }
  67.        
  68.        
  69.         /// <devdoc>
  70.         /// Convert the given value to a string using the given CultureInfo
  71.         /// </devdoc>
  72.         internal override object FromString(string value, CultureInfo culture)
  73.         {
  74.             return Single.Parse(value, culture);
  75.         }
  76.        
  77.         /// <devdoc>
  78.         /// Convert the given value from a string using the given formatInfo
  79.         /// </devdoc>
  80.         internal override string ToString(object value, NumberFormatInfo formatInfo)
  81.         {
  82.             return ((float)value).ToString("R", formatInfo);
  83.         }
  84.     }
  85. }

Developer Fusion