The Labs \ Source Viewer \ SSCLI \ System \ Currency

  1. // ==++==
  2. //
  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. //
  14. // ==--==
  15. namespace System
  16. {
  17.    
  18.     using System;
  19.     using System.Globalization;
  20.     using System.Runtime.CompilerServices;
  21.     [Serializable()]
  22.     internal struct Currency
  23.     {
  24.         internal long m_value;
  25.        
  26.         // Constructs a Currency from a Decimal value.
  27.         //
  28.         public Currency(decimal value)
  29.         {
  30.             m_value = Decimal.ToCurrency(value).m_value;
  31.         }
  32.        
  33.         // Constructs a Currency from a long value without scaling. The
  34.         // ignored parameter exists only to distinguish this constructor
  35.         // from the constructor that takes a long. Used only in the System
  36.         // package, especially in Variant.
  37.         internal Currency(long value, int ignored)
  38.         {
  39.             m_value = value;
  40.         }
  41.        
  42.         // Creates a Currency from an OLE Automation Currency. This method
  43.         // applies no scaling to the Currency value, essentially doing a bitwise
  44.         // copy.
  45.         //
  46.         public static Currency FromOACurrency(long cy)
  47.         {
  48.             return new Currency(cy, 0);
  49.         }
  50.        
  51.         //Creates an OLE Automation Currency from a Currency instance. This
  52.         // method applies no scaling to the Currency value, essentially doing
  53.         // a bitwise copy.
  54.         //
  55.         public long ToOACurrency()
  56.         {
  57.             return m_value;
  58.         }
  59.        
  60.         // Converts a Currency to a Decimal.
  61.         //
  62.         public static decimal ToDecimal(Currency c)
  63.         {
  64.             decimal result = new decimal();
  65.             FCallToDecimal(ref result, c);
  66.             return result;
  67.         }
  68.        
  69.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  70.         private static extern void FCallToDecimal(ref decimal result, Currency c);
  71.     }
  72. }

Developer Fusion