The Labs \ Source Viewer \ SSCLI \ System \ IConvertible

  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.Threading;
  19.    
  20.     // The IValue interface represents an object that contains a value. This
  21.     // interface is implemented by the following types in the System namespace:
  22.     // Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64,
  23.     // Single, Double, Decimal, DateTime, TimeSpan, and String. The interface may
  24.     // be implemented by other types that are to be considered values. For example,
  25.     // a library of nullable database types could implement IValue.
  26.     //
  27.     // The implementations of IValue provided by the System.XXX value classes
  28.     // simply forward to the appropriate Value.ToXXX(YYY) methods (a description of
  29.     // the Value class follows below). In cases where a Value.ToXXX(YYY) method
  30.     // does not exist (because the particular conversion is not supported), the
  31.     // IValue implementation should simply throw an InvalidCastException.
  32.    
  33.     [CLSCompliant(false)]
  34.     [System.Runtime.InteropServices.ComVisible(true)]
  35.     public interface IConvertible
  36.     {
  37.         // Returns the type code of this object. An implementation of this method
  38.         // must not return TypeCode.Empty (which represents a null reference) or
  39.         // TypeCode.Object (which represents an object that doesn't implement the
  40.         // IValue interface). An implementation of this method should return
  41.         // TypeCode.DBNull if the value of this object is a database null. For
  42.         // example, a nullable integer type should return TypeCode.DBNull if the
  43.         // value of the object is the database null. Otherwise, an implementation
  44.         // of this method should return the TypeCode that best describes the
  45.         // internal representation of the object.
  46.        
  47.         TypeCode GetTypeCode();
  48.        
  49.         // The ToXXX methods convert the value of the underlying object to the
  50.         // given type. If a particular conversion is not supported, the
  51.         // implementation must throw an InvalidCastException. If the value of the
  52.         // underlying object is not within the range of the target type, the
  53.         // implementation must throw an OverflowException. The
  54.         // IFormatProvider will be used to get a NumberFormatInfo or similar
  55.         // appropriate service object, and may safely be null.
  56.        
  57.         bool ToBoolean(IFormatProvider provider);
  58.         char ToChar(IFormatProvider provider);
  59.         sbyte ToSByte(IFormatProvider provider);
  60.         byte ToByte(IFormatProvider provider);
  61.         short ToInt16(IFormatProvider provider);
  62.         ushort ToUInt16(IFormatProvider provider);
  63.         int ToInt32(IFormatProvider provider);
  64.         uint ToUInt32(IFormatProvider provider);
  65.         long ToInt64(IFormatProvider provider);
  66.         ulong ToUInt64(IFormatProvider provider);
  67.         float ToSingle(IFormatProvider provider);
  68.         double ToDouble(IFormatProvider provider);
  69.         decimal ToDecimal(IFormatProvider provider);
  70.         DateTime ToDateTime(IFormatProvider provider);
  71.         string ToString(IFormatProvider provider);
  72.         object ToType(Type conversionType, IFormatProvider provider);
  73.     }
  74.    
  75. }

Developer Fusion