DataObject.GetData 方法

定义

返回指定数据格式的数据。Returns data in a specified data format.

重载

GetData(String)

返回指定格式的数据,此格式由字符串指定。Returns data in a format specified by a string.

GetData(Type)

返回指定格式的数据对象,此格式由 Type 对象指定。Returns a data object in a format specified by a Type object.

GetData(String, Boolean)

返回指定格式的数据对象,可选择将数据转换为指定格式。Returns a data object in a specified format, optionally converting the data to the specified format.

GetData(String)

返回指定格式的数据,此格式由字符串指定。Returns data in a format specified by a string.

public:
 virtual System::Object ^ GetData(System::String ^ format);
public object GetData (string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Function GetData (format As String) As Object

参数

format
String

一个指定数据格式的字符串。A string that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。For a set of predefined data formats, see the DataFormats class.

返回

Object

包含指定格式数据的对象;如果没有指定格式的数据,则为 nullAn object that contains the data in the specified format, or null if the data is unavailable in the specified format.

实现

例外

formatnullformat is null.

示例

下面的示例使用此方法首先检查指定的数据格式是否 (本机或自动转换) 中可用;如果指定的格式可用,则该示例使用方法检索数据 GetData(String)The following example uses this method to first check whether a specified data format is available (natively or by auto-convert); if the specified format is available, the example retrieves the data by using the GetData(String) method.

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// This particular overload of GetDataPresent looks for both native and auto-convertible 
// data formats.
if (dataObject.GetDataPresent(desiredFormat))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' This particular overload of GetDataPresent looks for both native and auto-convertible 
' data formats.
If dataObject.GetDataPresent(desiredFormat) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

下面的示例代码使用 GetDataPresent(String, Boolean) 方法首先检查指定的数据格式是否在本机可用 (是否筛选了可自动转换的数据格式) ; 如果指定的格式可用,则该示例使用方法检索数据 GetData(String)The following example code uses the GetDataPresent(String, Boolean) method to first check if a specified data format is available natively (auto-convertible data formats are filtered); if the specified format is available, the example retrieves the data by using the GetData(String) method.

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
bool noAutoConvert = false;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// The autoconvert parameter is set to false to filter out auto-convertible data formats,
// returning true only if the specified data format is available natively.
if (dataObject.GetDataPresent(desiredFormat, noAutoConvert))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim noAutoConvert As Boolean = False
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' The autoconvert parameter is set to false to filter out auto-convertible data formats,
' returning true only if the specified data format is available natively.
If dataObject.GetDataPresent(desiredFormat, noAutoConvert) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

适用于

GetData(Type)

返回指定格式的数据对象,此格式由 Type 对象指定。Returns a data object in a format specified by a Type object.

public:
 virtual System::Object ^ GetData(Type ^ format);
public object GetData (Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
Public Function GetData (format As Type) As Object

参数

format
Type

一个 Type,指定数据的格式。A Type that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。For a set of predefined data formats, see the DataFormats class.

返回

Object

包含指定格式数据的数据对象;如果没有指定格式的数据,则为 nullA data object with the data in the specified format, or null if the data is unavailable in the specified format.

实现

例外

formatnullformat is null.

适用于

GetData(String, Boolean)

返回指定格式的数据对象,可选择将数据转换为指定格式。Returns a data object in a specified format, optionally converting the data to the specified format.

public:
 virtual System::Object ^ GetData(System::String ^ format, bool autoConvert);
public object GetData (string format, bool autoConvert);
abstract member GetData : string * bool -> obj
override this.GetData : string * bool -> obj
Public Function GetData (format As String, autoConvert As Boolean) As Object

参数

format
String

一个指定数据格式的字符串。A string that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。For a set of predefined data formats, see the DataFormats class.

autoConvert
Boolean

若尝试自动将数据转换为指定格式,则为 true;若不进行数据格式转换,则为 falsetrue to attempt to automatically convert the data to the specified format; false for no data format conversion.

返回

Object

包含指定格式数据的数据对象;如果没有指定格式的数据,则为 nullA data object with the data in the specified format, or null if the data is unavailable in the specified format.

如果 autoConvert 参数为 true,且无法将数据转换为指定格式或自动转换被禁用(调用 SetData(String, Object, Boolean) 时将 autoConvert 参数设置为 false),则此方法返回 nullIf the autoConvert parameter is true and the data cannot be converted to the specified format, or if automatic conversion is disabled (by calling SetData(String, Object, Boolean) with the autoConvert parameter set to false), this method returns null.

实现

例外

format 为 null。format is null.

适用于