Binder.ChangeType 方法

将给定 Object 的类型更改为给定 Type

**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public MustOverride Function ChangeType ( _
    value As Object, _
    type As Type, _
    culture As CultureInfo _
) As Object
用法
Dim instance As Binder
Dim value As Object
Dim type As Type
Dim culture As CultureInfo
Dim returnValue As Object

returnValue = instance.ChangeType(value, type, culture)
public abstract Object ChangeType (
    Object value,
    Type type,
    CultureInfo culture
)
public:
virtual Object^ ChangeType (
    Object^ value, 
    Type^ type, 
    CultureInfo^ culture
) abstract
public abstract Object ChangeType (
    Object value, 
    Type type, 
    CultureInfo culture
)
public abstract function ChangeType (
    value : Object, 
    type : Type, 
    culture : CultureInfo
) : Object

参数

  • value
    要更改为新 Type 的值。
  • type
    value 将变成的新 Type
  • culture
    CultureInfo 的一个实例,用于控制数据类型强制。如果 culture 为 空引用(在 Visual Basic 中为 Nothing),则使用当前线程的 CultureInfo

    提示

    例如,将表示 1000 的 String 转换为 Double 值需要该参数,因为不同的区域性表示 1000 的形式不同。

返回值

包含作为新类型的给定值的 Object

备注

“反射”建立通用类型系统的可访问规则模型。例如,如果调用方在相同的程序集内,则它不需要内部成员的特殊权限。否则,调用方需要 ReflectionPermission。这与保护成员、私有成员等成员的查找是一致的。

一般原则是 ChangeType 应该只执行拓宽强制,后者从不丢失数据。扩展强制的一个例子是将 32 位有符号整数值强制为 64 位有符号整数值。这与窄缩强制不同,后者可能丢失数据。窄缩强制的一个例子是将 64 位有符号整数强制为 32 位有符号整数。

下表列出了默认的 ChangeType 执行的强制。

源类型

目标类型

任何类型

它的基类型。

任何类型

它实现的接口。

Char

UInt16、UInt32、Int32、UInt64、Int64、Single、Double

Byte

Char、UInt16、Int16、UInt32、Int32、UInt64、Int64、Single、Double

SByte

Int16、Int32、Int64、Single、Double

UInt16

UInt32、Int32、UInt64、Int64、Single、Double

Int16

Int32、Int64、Single、Double

UInt32

UInt64、Int64、Single、Double

Int32

Int64、Single、Double

UInt64

Single、Double

Int64

Single、Double

Single

Double

非引用

通过引用。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Binder 类
Binder 成员
System.Reflection 命名空间