DataContractSerializer.IsStartObject 메서드

정의

역직렬화할 수 있는 개체에 판독기가 배치되는지 여부를 확인합니다.

오버로드

IsStartObject(XmlReader)

역직렬화할 수 있는 개체에 XmlReader가 배치되는지 여부를 확인합니다.

IsStartObject(XmlDictionaryReader)

역직렬화할 수 있는 개체에 XmlDictionaryReader가 배치되는지 여부를 확인합니다.

IsStartObject(XmlReader)

역직렬화할 수 있는 개체에 XmlReader가 배치되는지 여부를 확인합니다.

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

매개 변수

reader
XmlReader

XML 스트림을 읽는 데 사용되는 XmlReader입니다.

반환

Boolean

판독기가 읽을 스트림의 시작 요소에 있으면 true이고, 그렇지 않으면 false입니다.

적용 대상

IsStartObject(XmlDictionaryReader)

역직렬화할 수 있는 개체에 XmlDictionaryReader가 배치되는지 여부를 확인합니다.

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

매개 변수

reader
XmlDictionaryReader

XML 스트림을 읽는 데 사용되는 XmlDictionaryReader입니다.

반환

Boolean

판독기가 읽을 스트림의 시작 요소에 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 속성을 사용 하 여 IsStartObject 데이터의 시작이 발견 되었는지 여부를 확인 합니다.

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

설명

개체 IsStartObject 가 XML 요소에 배치되어 있는지 확인하여 개체를 읽을 수 있는지 여부를 결정합니다. 또한 판독기에서 배치되는 XML 요소의 이름과 네임스페이스를 검사하고 값을 예상 이름 및 네임스페이스와 비교합니다. 예상 이름 및 네임스페이스는 생성자로 전달된 형식의 데이터 계약 이름과 네임스페이스 또는 생성자로 전달된 rootNamerootNamespace 값(있는 경우)을 사용하여 설정될 수 있습니다.

적용 대상