DataObject.GetDataPresent Metoda

Definicja

Określa, czy dane są dostępne w określonym formacie, czy można je przekonwertować.

Przeciążenia

GetDataPresent(String)

Określa, czy dane są dostępne w, czy można je przekonwertować na format określony przez ciąg.

GetDataPresent(Type)

Określa, czy dane są dostępne w, czy można je przekonwertować na format określony przez Type obiekt.

GetDataPresent(String, Boolean)

Określa, czy dane są dostępne w określonym formacie, czy można je przekonwertować. Flaga Boolean wskazuje, czy dane można przekonwertować na określony format, jeśli nie są dostępne w tym formacie.

Uwagi

Wywołaj metodę GetDataPresent , aby określić, czy format jest dostępny w tym obiekcie danych przed wywołaniem metody GetData. Wywołaj metodę GetFormats , aby uzyskać listę wszystkich formatów dostępnych w tym obiekcie danych.

GetDataPresent(String)

Określa, czy dane są dostępne w, czy można je przekonwertować na format określony przez ciąg.

public:
 virtual bool GetDataPresent(System::String ^ format);
public bool GetDataPresent (string format);
abstract member GetDataPresent : string -> bool
override this.GetDataPresent : string -> bool
Public Function GetDataPresent (format As String) As Boolean

Parametry

format
String

Ciąg określający format danych. Aby uzyskać zestaw wstępnie zdefiniowanych formatów danych, zobacz klasę DataFormats .

Zwraca

Boolean

true jeśli dane są w, lub można je przekonwertować na, określony format; w przeciwnym razie , false.

Implementuje

Wyjątki

format to null.

Przykłady

W poniższym przykładzie użyto tej metody do wykonywania zapytań o obecność określonego formatu danych według ciągu deskryptora.

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

// Query for the presence of Text data in the data object, by a data format descriptor string.
// In this overload of GetDataPresent, the method will return true both for native data formats
// and when the data can automatically be converted to the specifed format.

// In this case, string data is present natively, so GetDataPresent returns "true".
string textData = null;
if (dataObject.GetDataPresent(DataFormats.StringFormat))
{
    textData = dataObject.GetData(DataFormats.StringFormat) as string;
}

// In this case, the Text data in the data object can be autoconverted to 
// Unicode text, so GetDataPresent returns "true".
byte[] unicodeData = null;
if (dataObject.GetDataPresent(DataFormats.UnicodeText))
{
    unicodeData = dataObject.GetData(DataFormats.UnicodeText) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

' Query for the presence of Text data in the data object, by a data format descriptor string.
' In this overload of GetDataPresent, the method will return true both for native data formats
' and when the data can automatically be converted to the specifed format.

' In this case, string data is present natively, so GetDataPresent returns "true".
Dim textData As String = Nothing
If dataObject.GetDataPresent(DataFormats.StringFormat) Then
    textData = TryCast(dataObject.GetData(DataFormats.StringFormat), String)
End If

' In this case, the Text data in the data object can be autoconverted to 
' Unicode text, so GetDataPresent returns "true".
Dim unicodeData() As Byte = Nothing
If dataObject.GetDataPresent(DataFormats.UnicodeText) Then
    unicodeData = TryCast(dataObject.GetData(DataFormats.UnicodeText), Byte())
End If

Uwagi

Wywołaj metodę GetDataPresent , aby określić, czy format jest dostępny w tym obiekcie danych przed wywołaniem metody GetData. Wywołaj metodę GetFormats , aby uzyskać listę wszystkich formatów dostępnych w tym obiekcie danych.

Zobacz też

Dotyczy

GetDataPresent(Type)

Określa, czy dane są dostępne w, czy można je przekonwertować na format określony przez Type obiekt.

public:
 virtual bool GetDataPresent(Type ^ format);
public bool GetDataPresent (Type format);
abstract member GetDataPresent : Type -> bool
override this.GetDataPresent : Type -> bool
Public Function GetDataPresent (format As Type) As Boolean

Parametry

format
Type

Element Type określający format danych do sprawdzenia. F lub zestaw wstępnie zdefiniowanych formatów danych, zobacz klasę DataFormats .

Zwraca

Boolean

true jeśli dane są w, lub można je przekonwertować na, określony format; w przeciwnym razie , false.

Implementuje

Wyjątki

format to null.

Przykłady

W poniższym przykładzie użyto tej metody do wykonywania zapytań o obecność określonego formatu danych według typu.

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

// Query for the presence of String data in the data object, by type.  In this overload 
// of GetDataPresent, the method will return true both for native data formats
// and when the data can automatically be converted to the specifed format.

// In this case, the Text data present in the data object can be autoconverted
// to type string (also represented by DataFormats.String), so GetDataPresent returns "true".
string stringData = null;
if (dataObject.GetDataPresent(typeof(string)))
{
    stringData = dataObject.GetData(DataFormats.Text) as string;
}
Dim dataObject As New DataObject("Some string data to store...")

' Query for the presence of String data in the data object, by type.  In this overload 
' of GetDataPresent, the method will return true both for native data formats
' and when the data can automatically be converted to the specifed format.

' In this case, the Text data present in the data object can be autoconverted
' to type string (also represented by DataFormats.String), so GetDataPresent returns "true".
Dim stringData As String = Nothing
If dataObject.GetDataPresent(GetType(String)) Then
    stringData = TryCast(dataObject.GetData(DataFormats.Text), String)
End If

Uwagi

Wywołaj metodę GetDataPresent , aby określić, czy format jest dostępny w tym obiekcie danych przed wywołaniem metody GetData. Wywołaj metodę GetFormats , aby uzyskać listę wszystkich formatów dostępnych w tym obiekcie danych.

Zobacz też

Dotyczy

GetDataPresent(String, Boolean)

Określa, czy dane są dostępne w określonym formacie, czy można je przekonwertować. Flaga Boolean wskazuje, czy dane można przekonwertować na określony format, jeśli nie są dostępne w tym formacie.

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

Parametry

format
String

Ciąg określający format danych do sprawdzenia. Aby uzyskać zestaw wstępnie zdefiniowanych formatów danych, zobacz klasę DataFormats .

autoConvert
Boolean

false aby sprawdzić tylko określony format; true aby sprawdzić również, czy dane przechowywane w tym obiekcie danych można przekonwertować na określony format.

Zwraca

Boolean

true jeśli dane są w, lub można je przekonwertować na, określony format; w przeciwnym razie , false.

Implementuje

Wyjątki

format to null.

Przykłady

W poniższym przykładzie użyto tej metody do wykonywania zapytań o dane według ciągu deskryptora i określa sposób traktowania formatów danych automatycznie konwertowanych.

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

// Query for the presence of Text data in the data object, by data format descriptor string,
// and specifying whether auto-convertible data formats are acceptable.  

// In this case, Text data is present natively, so GetDataPresent returns "true".
string textData = null;
if (dataObject.GetDataPresent(DataFormats.Text, false /* Auto-convert? */))
{
    textData = dataObject.GetData(DataFormats.Text) as string;
}

// In this case, the Text data in the data object can be autoconverted to 
// Unicode text, but it is not available natively, so GetDataPresent returns "false".
byte[] unicodeData = null;
if (dataObject.GetDataPresent(DataFormats.UnicodeText, false /* Auto-convert? */))
{
    unicodeData = dataObject.GetData(DataFormats.UnicodeText) as byte[];
}

// In this case, the Text data in the data object can be autoconverted to 
// Unicode text, so GetDataPresent returns "true".
if (dataObject.GetDataPresent(DataFormats.UnicodeText, true /* Auto-convert? */))
{
    unicodeData = dataObject.GetData(DataFormats.UnicodeText) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

' Query for the presence of Text data in the data object, by data format descriptor string,
' and specifying whether auto-convertible data formats are acceptable.  

' In this case, Text data is present natively, so GetDataPresent returns "true".
Dim textData As String = Nothing
If dataObject.GetDataPresent(DataFormats.Text, False) Then ' Auto-convert? 
    textData = TryCast(dataObject.GetData(DataFormats.Text), String)
End If

' In this case, the Text data in the data object can be autoconverted to 
' Unicode text, but it is not available natively, so GetDataPresent returns "false".
Dim unicodeData() As Byte = Nothing
If dataObject.GetDataPresent(DataFormats.UnicodeText, False) Then ' Auto-convert? 
    unicodeData = TryCast(dataObject.GetData(DataFormats.UnicodeText), Byte())
End If

' In this case, the Text data in the data object can be autoconverted to 
' Unicode text, so GetDataPresent returns "true".
If dataObject.GetDataPresent(DataFormats.UnicodeText, True) Then ' Auto-convert? 
    unicodeData = TryCast(dataObject.GetData(DataFormats.UnicodeText), Byte())
End If

Uwagi

Wywołaj metodę GetDataPresent , aby określić, czy format jest dostępny w tym obiekcie danych przed wywołaniem metody GetData. Wywołaj metodę GetFormats , aby uzyskać listę wszystkich formatów dostępnych w tym obiekcie danych.

Zobacz też

Dotyczy