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


C# YAXSerializer.SerializeToFile方法代码示例

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


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

示例1: OnSerialize

        private void OnSerialize(bool saveToFile)
        {
            object selItem = lstSampleClasses.SelectedItem;
            if (selItem == null || !(selItem is ClassInfoListItem))
                return;

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

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

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

                if (saveToFile)
                    serializer.SerializeToFile(info.SampleObject, fileName);
                else
                    rtbXMLOutput.Text = serializer.Serialize(info.SampleObject);
                rtbParsingErrors.Text = serializer.ParsingErrors.ToString();
            }
            catch (YAXException ex)
            {
                MessageBox.Show("YAXException handled:\r\n\r\n" + ex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Other Exception handled:\r\n\r\n" + ex.ToString());
            }
        }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:39,代码来源:FormMain.cs

示例2: SaveState

        public void SaveState(string fileName, uint simulationStep)
        {
            try
            {
                string dataFolder = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".statedata";

                MyNetworkState networkState = new MyNetworkState()
                {
                    ProjectName = Owner.Name,
                    MemoryBlocksLocation = dataFolder,
                    SimulationStep = simulationStep
                };

                YAXSerializer serializer = new YAXSerializer(typeof(MyNetworkState),
                    YAXExceptionHandlingPolicies.ThrowErrorsOnly,
                    YAXExceptionTypes.Warning);

                serializer.SerializeToFile(networkState, fileName);

                if (Directory.Exists(dataFolder))
                {
                    Directory.Delete(dataFolder, true);
                }

                Directory.CreateDirectory(dataFolder);
                MyMemoryManager.Instance.SaveBlocks(this, true, dataFolder);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Saving state failed: " + e.Message);
            }
        }
开发者ID:J-F-B-M,项目名称:BrainSimulator,代码行数:32,代码来源:MyNetwork.cs

示例3: exportStateButton_Click

        private void exportStateButton_Click(object sender, EventArgs e)
        {
            if (saveMemFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    string dataFolder = MyProject.MakeDataFolderFromFileName(saveMemFileDialog.FileName);
                    
                    MyMemoryBlockSerializer.ExportTempStorage(Project, dataFolder);

                    MyNetworkState networkState = new MyNetworkState()
                    {
                        ProjectName = Project.Name,
                        MemoryBlocksLocation = dataFolder,
                        SimulationStep = SimulationHandler.SimulationStep
                    };

                    YAXSerializer serializer = new YAXSerializer(typeof(MyNetworkState),
                        YAXExceptionHandlingPolicies.ThrowErrorsOnly,
                        YAXExceptionTypes.Warning);

                    serializer.SerializeToFile(networkState, saveMemFileDialog.FileName);
                    MyLog.INFO.WriteLine("Saving state: " + saveMemFileDialog.FileName);
                }
                catch (Exception ex)
                {
                    MyLog.ERROR.WriteLine("Saving state failed: " + ex.Message);
                }    
            }
        }
开发者ID:GoodAI,项目名称:BrainSimulator,代码行数:30,代码来源:MainForm.cs

示例4: Save

 public void Save()
 {
     var serializer = new YAXSerializer(typeof(NuspecModel), YAXExceptionHandlingPolicies.ThrowWarningsAndErrors,
         YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);
     serializer.SerializeToFile(model, fileLocation);
 }
开发者ID:black-virus,项目名称:local-nuget,代码行数:6,代码来源:Nuspec.cs


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