DataContractSerializer.IsStartObject Metode

Definisi

Menentukan apakah pembaca diposisikan pada objek yang dapat dideserialisasi.

Overload

Nama Deskripsi
IsStartObject(XmlReader)

Menentukan apakah XmlReader diposisikan pada objek yang dapat dideserialisasi.

IsStartObject(XmlDictionaryReader)

Menentukan apakah XmlDictionaryReader diposisikan pada objek yang dapat dideserialisasi.

IsStartObject(XmlReader)

Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs

Menentukan apakah XmlReader diposisikan pada objek yang dapat dideserialisasi.

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

Parameter

reader
XmlReader

yang XmlReader digunakan untuk membaca aliran XML.

Mengembalikan

true jika pembaca berada di elemen awal aliran untuk dibaca; jika tidak, false.

Atribut

Berlaku untuk

IsStartObject(XmlDictionaryReader)

Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs
Sumber:
DataContractSerializer.cs

Menentukan apakah XmlDictionaryReader diposisikan pada objek yang dapat dideserialisasi.

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

Parameter

reader
XmlDictionaryReader

Digunakan XmlDictionaryReader untuk membaca aliran XML.

Mengembalikan

true jika pembaca berada di elemen awal aliran untuk dibaca; jika tidak, false.

Atribut

Contoh

Contoh berikut menggunakan IsStartObject properti untuk menentukan apakah awal data telah ditemukan.

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

Keterangan

IsStartObject menentukan apakah objek dapat dibaca dengan memeriksa apakah objek tersebut diposisikan pada elemen XML. Ini juga memeriksa nama dan namespace elemen XML yang diposisikan pembaca dan membandingkan nilai dengan nama dan namespace yang diharapkan. Nama dan namespace yang diharapkan dapat diatur dengan yang berikut: nama kontrak data dan namespace jenis yang diteruskan ke konstruktor, atau rootName nilai dan rootNamespace yang diteruskan ke konstruktor (jika ada).

Berlaku untuk