Condividi tramite


DataObject.GetDataPresent Metodo

Definizione

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato.

Overload

Nome Descrizione
GetDataPresent(String)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato da una stringa.

GetDataPresent(Type)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato da un Type oggetto .

GetDataPresent(String, Boolean)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato. Un Boolean flag indica se verificare se i dati possono essere convertiti nel formato specificato se non sono disponibili in tale formato.

Commenti

Chiamare GetDataPresent per determinare se un formato è disponibile in questo oggetto dati prima di chiamare GetData. Chiamare GetFormats per ottenere un elenco di tutti i formati disponibili in questo oggetto dati.

GetDataPresent(String)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato da una stringa.

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

Parametri

format
String

Stringa che specifica il formato per i dati. Per un set di formati di dati predefiniti, vedere la DataFormats classe .

Valori restituiti

true se i dati sono in o possono essere convertiti in, il formato specificato; in caso contrario, false.

Implementazioni

Eccezioni

format è null.

Esempio

Nell'esempio seguente viene usato questo metodo per eseguire una query sulla presenza di un particolare formato di dati in base alla stringa del descrittore.

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

Commenti

Chiamare GetDataPresent per determinare se un formato è disponibile in questo oggetto dati prima di chiamare GetData. Chiamare GetFormats per ottenere un elenco di tutti i formati disponibili in questo oggetto dati.

Vedi anche

Si applica a

GetDataPresent(Type)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato da un Type oggetto .

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

Parametri

format
Type

Oggetto Type che specifica il formato di dati da controllare. F o un set di formati di dati predefiniti, vedere la DataFormats classe .

Valori restituiti

true se i dati sono in o possono essere convertiti in, il formato specificato; in caso contrario, false.

Implementazioni

Eccezioni

format è null.

Esempio

Nell'esempio seguente viene usato questo metodo per eseguire una query sulla presenza di un particolare formato di dati per tipo.

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

Commenti

Chiamare GetDataPresent per determinare se un formato è disponibile in questo oggetto dati prima di chiamare GetData. Chiamare GetFormats per ottenere un elenco di tutti i formati disponibili in questo oggetto dati.

Vedi anche

Si applica a

GetDataPresent(String, Boolean)

Determina se i dati sono disponibili in o possono essere convertiti in un formato specificato. Un Boolean flag indica se verificare se i dati possono essere convertiti nel formato specificato se non sono disponibili in tale formato.

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

Parametri

format
String

Stringa che specifica il formato di dati da controllare. Per un set di formati di dati predefiniti, vedere la DataFormats classe .

autoConvert
Boolean

false per verificare solo il formato specificato; true per verificare anche se i dati archiviati in questo oggetto dati possono essere convertiti nel formato specificato.

Valori restituiti

true se i dati sono in o possono essere convertiti in, il formato specificato; in caso contrario, false.

Implementazioni

Eccezioni

format è null.

Esempio

Nell'esempio seguente viene usato questo metodo per eseguire query sui dati in base alla stringa del descrittore e viene specificato come trattare i formati di dati convertibili automaticamente.

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

Commenti

Chiamare GetDataPresent per determinare se un formato è disponibile in questo oggetto dati prima di chiamare GetData. Chiamare GetFormats per ottenere un elenco di tutti i formati disponibili in questo oggetto dati.

Vedi anche

Si applica a