當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。