DataContractSerializer.IsStartObject Metoda

Definice

Určuje, zda je čtenář umístěn na objektu, který lze deserializovat.

Přetížení

Name Description
IsStartObject(XmlReader)

Určuje, zda je umístěn XmlReader na objektu, který lze deserializovat.

IsStartObject(XmlDictionaryReader)

Určuje, zda je umístěn XmlDictionaryReader na objektu, který lze deserializovat.

IsStartObject(XmlReader)

Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs

Určuje, zda je umístěn XmlReader na objektu, který lze deserializovat.

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

Parametry

reader
XmlReader

Používá XmlReader se ke čtení datového proudu XML.

Návraty

trueje-li čtenář na začátku prvku datového proudu ke čtení; v opačném případě . false

Atributy

Platí pro

IsStartObject(XmlDictionaryReader)

Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs
Zdroj:
DataContractSerializer.cs

Určuje, zda je umístěn XmlDictionaryReader na objektu, který lze deserializovat.

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

Parametry

reader
XmlDictionaryReader

Používá XmlDictionaryReader se ke čtení datového proudu XML.

Návraty

trueje-li čtenář na začátku prvku datového proudu ke čtení; v opačném případě . false

Atributy

Příklady

Následující příklad používá IsStartObject vlastnost k určení, zda byl nalezen začátek dat.

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

Poznámky

Určuje IsStartObject , zda může číst objekt tím, že zkontroluje, zda je umístěn v elementu XML. Zkoumá také název a obor názvů elementu XML, na který je čtenář umístěn a porovnává hodnoty s očekávaným názvem a oborem názvů. Očekávaný název a obor názvů lze nastavit takto: název kontraktu dat a obor názvů typu předaného do konstruktoru nebo rootName hodnoty a rootNamespace hodnoty předané do konstruktoru (pokud existují).

Platí pro