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


C# YAXSerializer.DeserializeFromFile方法代码示例

本文整理汇总了C#中YAXLib.YAXSerializer.DeserializeFromFile方法的典型用法代码示例。如果您正苦于以下问题:C# YAXSerializer.DeserializeFromFile方法的具体用法?C# YAXSerializer.DeserializeFromFile怎么用?C# YAXSerializer.DeserializeFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YAXLib.YAXSerializer的用法示例。


在下文中一共展示了YAXSerializer.DeserializeFromFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryYax

        private static void TryYax()
        {
            var obj = CreateFakeObject();
            obj.SetValues();

            var serializer = new YAXSerializer(typeof(Parameters),
                YAXExceptionHandlingPolicies.DoNotThrow,YAXExceptionTypes.Error,
                YAXSerializationOptions.DontSerializeCyclingReferences|YAXSerializationOptions.DontSerializeNullObjects|YAXSerializationOptions.DontSerializePropertiesWithNoSetter);
            var someString = serializer.Serialize(obj);
            File.WriteAllText("yax.xml", someString);

            var back = serializer.DeserializeFromFile("yax.xml");
        }
开发者ID:cuipengfei,项目名称:Spikes,代码行数:13,代码来源:Program.cs

示例2: LoadState

        public MyNetworkState LoadState(string fileName)
        {
            try
            {
                YAXSerializer serializer = new YAXSerializer(typeof(MyNetworkState),
                    YAXExceptionHandlingPolicies.ThrowErrorsOnly,
                    YAXExceptionTypes.Warning);

                MyNetworkState networkState = (MyNetworkState)serializer.DeserializeFromFile(fileName);

                if (Owner.Name != networkState.ProjectName)
                {
                    throw new InvalidDataException("Different network state file: " + networkState.ProjectName);
                }
                MyMemoryManager.Instance.LoadBlocks(this, true, networkState.MemoryBlocksLocation);

                return networkState;
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Restoring state failed: " + e.Message);
                return new MyNetworkState();
            }
        }
开发者ID:J-F-B-M,项目名称:BrainSimulator,代码行数:24,代码来源:MyNetwork.cs

示例3: OnDeserialize

        private void OnDeserialize(bool openFromFile)
        {
            rtbParsingErrors.Text = "";
            object selItem = lstSampleClasses.SelectedItem;
            if (selItem == null || !(selItem is ClassInfoListItem))
                return;

            string fileName = null;
            if (openFromFile)
            {
                if (DialogResult.OK != openFileDialog1.ShowDialog())
                    return;
                fileName = openFileDialog1.FileName;
            }

            var info = selItem as ClassInfoListItem;
            YAXExceptionTypes defaultExType = GetSelectedDefaultExceptionType();
            YAXExceptionHandlingPolicies exPolicy = GetSelectedExceptionHandlingPolicy();
            YAXSerializationOptions serOption = GetSelectedSerializationOption();

            try
            {
                object deserializedObject = null;
                YAXSerializer serializer = new YAXSerializer(info.ClassType, exPolicy, defaultExType, serOption);
                serializer.MaxRecursion = Convert.ToInt32(numMaxRecursion.Value);

                if (openFromFile)
                    deserializedObject = serializer.DeserializeFromFile(fileName);
                else
                    deserializedObject = serializer.Deserialize(rtbXMLOutput.Text);

                rtbParsingErrors.Text = serializer.ParsingErrors.ToString();

                if (deserializedObject != null)
                {
                    rtbDeserializeOutput.Text = deserializedObject.ToString();

                    if (deserializedObject is List<string>)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var item in deserializedObject as List<string>)
                        {
                            sb.AppendLine(item.ToString());
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
                else
                    rtbDeserializeOutput.Text = "The deserialized object is null";
            }
            catch (YAXException ex)
            {
                rtbDeserializeOutput.Text = "";
                MessageBox.Show("YAXException handled:\r\n\r\n" + ex.ToString());
            }
            catch (Exception ex)
            {
                rtbDeserializeOutput.Text = "";
                MessageBox.Show("Other Exception handled:\r\n\r\n" + ex.ToString());
            }
        }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:61,代码来源:FormMain.cs

示例4: InitFromXmlFile

 private void InitFromXmlFile(string xmlFile)
 {
     var serializer = new YAXSerializer(typeof(NuspecModel), YAXExceptionHandlingPolicies.ThrowWarningsAndErrors,
         YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);
     model = serializer.DeserializeFromFile(xmlFile) as NuspecModel;
     if (model == null) throw new Exception("Can't deseralize xml nuspec file");
 }
开发者ID:black-virus,项目名称:local-nuget,代码行数:7,代码来源:Nuspec.cs

示例5: LoadLanguage

 private static void LoadLanguage()
 {
     LanguageList.Clear();
     string[] xmlFileList = Directory.GetFiles(LanguageFolder, "*.xml");
     foreach (string xmlFile in xmlFileList)
     {
         YAXSerializer serializer = new YAXSerializer(typeof(Language));
         Language language =
             serializer.DeserializeFromFile(xmlFile) as Language;
         LanguageList.Add(language);
     }
 }
开发者ID:MuteG,项目名称:DevTools,代码行数:12,代码来源:LanguageManager.cs


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