当前位置: 首页>>代码示例>>C#>>正文


C# DataContractSerializer.IsStartObject方法代码示例

本文整理汇总了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
        }
开发者ID:cquinlan,项目名称:USBT,代码行数:31,代码来源:Xml.cs

示例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;
		}
开发者ID:RayBatts,项目名称:pwnsaw,代码行数:24,代码来源:Util.cs

示例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;
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:51,代码来源:Statistics.cs


注:本文中的System.Runtime.Serialization.DataContractSerializer.IsStartObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。