本文整理匯總了C#中System.Runtime.Serialization.DataContractSerializer.IsStartObject方法的典型用法代碼示例。如果您正苦於以下問題:C# DataContractSerializer.IsStartObject方法的具體用法?C# DataContractSerializer.IsStartObject怎麽用?C# DataContractSerializer.IsStartObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Runtime.Serialization.DataContractSerializer
的用法示例。
在下文中一共展示了DataContractSerializer.IsStartObject方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadObjectData
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();
}