本文整理匯總了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);
}