DataContractSerializer.IsStartObject Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Meghatározza, hogy az olvasó egy deszerializálható objektumon van-e elhelyezve.
Túlterhelések
| Name | Description |
|---|---|
| IsStartObject(XmlReader) |
Meghatározza, hogy az XmlReader objektum egy deszerializálható objektumon van-e elhelyezve. |
| IsStartObject(XmlDictionaryReader) |
Meghatározza, hogy az XmlDictionaryReader objektum egy deszerializálható objektumon van-e elhelyezve. |
IsStartObject(XmlReader)
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
Meghatározza, hogy az XmlReader objektum egy deszerializálható objektumon van-e elhelyezve.
public:
override bool IsStartObject(System::Xml::XmlReader ^ reader);
public override bool IsStartObject(System.Xml.XmlReader reader);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override bool IsStartObject(System.Xml.XmlReader reader);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override bool IsStartObject(System.Xml.XmlReader reader);
override this.IsStartObject : System.Xml.XmlReader -> bool
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.IsStartObject : System.Xml.XmlReader -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.IsStartObject : System.Xml.XmlReader -> bool
Public Overrides Function IsStartObject (reader As XmlReader) As Boolean
Paraméterek
Válaszok
trueha az olvasó a stream első eleménél van az olvasáshoz; egyéb esetben. false
- Attribútumok
A következőre érvényes:
IsStartObject(XmlDictionaryReader)
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
- Forrás:
- DataContractSerializer.cs
Meghatározza, hogy az XmlDictionaryReader objektum egy deszerializálható objektumon van-e elhelyezve.
public:
override bool IsStartObject(System::Xml::XmlDictionaryReader ^ reader);
public override bool IsStartObject(System.Xml.XmlDictionaryReader reader);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override bool IsStartObject(System.Xml.XmlDictionaryReader reader);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override bool IsStartObject(System.Xml.XmlDictionaryReader reader);
override this.IsStartObject : System.Xml.XmlDictionaryReader -> bool
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.IsStartObject : System.Xml.XmlDictionaryReader -> bool
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.IsStartObject : System.Xml.XmlDictionaryReader -> bool
Public Overrides Function IsStartObject (reader As XmlDictionaryReader) As Boolean
Paraméterek
- reader
- XmlDictionaryReader
Az XmlDictionaryReader XML-adatfolyam olvasásához használt.
Válaszok
trueha az olvasó a stream első eleménél van az olvasáshoz; egyéb esetben. false
- Attribútumok
Példák
Az alábbi példa a IsStartObject tulajdonságot használja annak megállapítására, hogy az adatok kezdete megtalálható-e.
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
Megjegyzések
A IsStartObject beállítás azt határozza meg, hogy képes-e beolvasni egy objektumot, ha ellenőrzi, hogy az XML-elemen van-e elhelyezve. Emellett megvizsgálja annak az XML-elemnek a nevét és névterét, amelynél az olvasó elhelyezkedik, és összehasonlítja az értékeket a várt névvel és névtérrel. A várt név és névtér a következőkkel állítható be: a konstruktornak átadott adatszerződés neve és névtere, vagy a rootName konstruktornak átadott értékek ( rootNamespace ha vannak).