本文整理汇总了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());
}
}
示例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);
}
}
示例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);
}
}
}
示例4: Save
public void Save()
{
var serializer = new YAXSerializer(typeof(NuspecModel), YAXExceptionHandlingPolicies.ThrowWarningsAndErrors,
YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);
serializer.SerializeToFile(model, fileLocation);
}