DataContractSerializer.IsStartObject Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se il lettore è posizionato su un oggetto che può essere deserializzato.
Overload
| IsStartObject(XmlReader) |
Determina se la classe XmlReader è posizionata su un oggetto che può essere deserializzato. |
| IsStartObject(XmlDictionaryReader) |
Determina se la classe XmlDictionaryReader è posizionata su un oggetto che può essere deserializzato. |
IsStartObject(XmlReader)
- Origine:
- DataContractSerializer.cs
- Origine:
- DataContractSerializer.cs
- Origine:
- DataContractSerializer.cs
Determina se la classe XmlReader è posizionata su un oggetto che può essere deserializzato.
public:
override bool IsStartObject(System::Xml::XmlReader ^ reader);
public override bool IsStartObject (System.Xml.XmlReader reader);
override this.IsStartObject : System.Xml.XmlReader -> bool
Public Overrides Function IsStartObject (reader As XmlReader) As Boolean
Parametri
Restituisce
true se il lettore si trova in corrispondenza dell'elemento iniziale del flusso da leggere. In caso contrario, false.
Si applica a
IsStartObject(XmlDictionaryReader)
- Origine:
- DataContractSerializer.cs
- Origine:
- DataContractSerializer.cs
- Origine:
- DataContractSerializer.cs
Determina se la classe XmlDictionaryReader è posizionata su un oggetto che può essere deserializzato.
public:
override bool IsStartObject(System::Xml::XmlDictionaryReader ^ reader);
public override bool IsStartObject (System.Xml.XmlDictionaryReader reader);
override this.IsStartObject : System.Xml.XmlDictionaryReader -> bool
Public Overrides Function IsStartObject (reader As XmlDictionaryReader) As Boolean
Parametri
- reader
- XmlDictionaryReader
Classe XmlDictionaryReader utilizzata per leggere il flusso XML.
Restituisce
true se il lettore si trova in corrispondenza dell'elemento iniziale del flusso da leggere. In caso contrario, false.
Esempio
Nell'esempio seguente viene utilizzata la proprietà IsStartObject per determinare se è stato rilevato l'inizio dei dati.
public static void ReadObjectData(string path)
{
// Create the reader.
FileStream fs = new FileStream(path, FileMode.Open);
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
// Create the DataContractSerializer specifying the type,
// root and namespace to use. The root value corresponds
// to the DataContract.Name value, and the namespace value
// corresponds to the DataContract.Namespace value.
DataContractSerializer ser =
new DataContractSerializer(typeof(Person),
"Customer", @"http://www.contoso.com");
// Test if the serializer is on the start of the
// object data. If so, read the data and write it
// to the console.
while (reader.Read())
{
if (ser.IsStartObject(reader))
{
Console.WriteLine("Found the element");
Person p = (Person)ser.ReadObject(reader);
Console.WriteLine("{0} {1} id:{2}",
p.FirstName, p.LastName, p.ID);
}
Console.WriteLine(reader.Name);
break;
}
fs.Flush();
fs.Close();
}
Public Shared Sub ReadObjectData(ByVal path As String)
' Create the reader.
Dim fs As New FileStream(path, FileMode.Open)
Dim reader As XmlDictionaryReader = _
XmlDictionaryReader.CreateTextReader(fs, New XmlDictionaryReaderQuotas())
' Create the DataContractSerializer specifying the type,
' root and namespace to use. The root value corresponds
' to the DataContract.Name value, and the namespace value
' corresponds to the DataContract.Namespace value.
Dim ser As New DataContractSerializer(GetType(Person), _
"Customer", "http://www.contoso.com")
' Test if the serializer is on the start of the
' object data. If so, read the data and write it
' to the console.
While reader.Read()
If ser.IsStartObject(reader) Then
Console.WriteLine("Found the element")
Dim p As Person = CType(ser.ReadObject(reader), Person)
Console.WriteLine("{0} {1} id:{2}", p.FirstName, p.LastName, p.ID)
End If
Console.WriteLine(reader.Name)
End While
fs.Flush()
fs.Close()
End Sub
Commenti
Il metodo IsStartObject determina se è possibile leggere un oggetto controllando che sia posizionato su un elemento XML. Esamina inoltre il nome e lo spazio dei nomi dell'elemento XML su cui è posizionato il lettore e confronta i valori con il nome e lo spazio dei nomi previsti. Il nome e lo spazio dei nomi previsti possono essere impostati con i valori seguenti: nome e spazio dei nomi del contratto dati del tipo passato al costruttore o valori rootName e rootNamespace passati al costruttore (se presenti).