本文整理汇总了C#中System.Runtime.Serialization.DataContractSerializer.IsStartObject方法的典型用法代码示例。如果您正苦于以下问题:C# DataContractSerializer.IsStartObject方法的具体用法?C# DataContractSerializer.IsStartObject怎么用?C# DataContractSerializer.IsStartObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.DataContractSerializer
的用法示例。
在下文中一共展示了DataContractSerializer.IsStartObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadOpsFile
public static IOperation[] loadOpsFile(string path, Type[] knownTypes)
{
//Open the operation file.
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
//Read in the file and store each item to a list. Type is "anyType" but this will be cast to IOperation.
DataContractSerializer serializer = new DataContractSerializer(typeof(IOperation), knownTypes);
XmlReader read = XmlReader.Create(fs);
read.ReadToDescendant("z:anyType");
List<IOperation> opList = new List<IOperation>();
//Blurahegle
while (serializer.IsStartObject(read))
{
//Check each type when deserializing. Make sure we can cast it.
try
{
opList.Add((IOperation)serializer.ReadObject(read));
}
catch (Exception e)
{
MessageBox.Show("Invalid operation type encountered. Please ensure all required libraies are installed \n" + e.Message, "An error has occured",MessageBoxButtons.OK,MessageBoxIcon.Error);
fs.Close();
return null;
}
}
fs.Close();
return opList.ToArray();
//Done
}
示例2: DeserializeHeroList
public static List< Hero > DeserializeHeroList( string combinedHeroXmlFile )
{
var heroSerializer = new DataContractSerializer( typeof( List<Hero> ) );
using( var dataFileStream = new FileStream( combinedHeroXmlFile, FileMode.Open ) )
{
var dictReader = XmlDictionaryReader.CreateTextReader( dataFileStream, new XmlDictionaryReaderQuotas() );
while( dictReader.Read() )
{
switch( dictReader.NodeType )
{
case XmlNodeType.Element:
if( heroSerializer.IsStartObject( dictReader ) )
{
return (List<Hero>)heroSerializer.ReadObject( dictReader );
}
break;
}
}
}
return null;
}
示例3: Load
public static Statistics Load()
{
Statistics statistics = null;
try
{
// TODO : This is not to be used for this release -- still some pondering to do.
return new Statistics();
DataContractSerializer serializer = new DataContractSerializer(typeof(Statistics), new Type[] { });
using (FileStream fs = new FileStream(Statistics.Filename, FileMode.Open))
{
using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (serializer.IsStartObject(reader))
{
statistics = (Statistics)serializer.ReadObject(reader);
}
break;
}
}
}
}
//using (StreamWriter swStatistics = new StreamWriter(Statistics.Filename))
//{
// using (XmlTextWriter writer = new XmlTextWriter(swStatistics))
// {
// writer.Formatting = Formatting.Indented;
// serializer.WriteObject(writer, this);
// writer.Flush();
// }
//}
//XmlSerializer mySerializer = new XmlSerializer(typeof(Statistics), new Type[] { });
//FileStream myFileStream = new FileStream(Statistics.Filename, FileMode.Open);
//statistics = (Statistics)mySerializer.Deserialize(myFileStream);
}
catch
{
statistics = new Statistics();
}
return statistics;
}