本文整理汇总了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");
}
示例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();
}
}
示例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());
}
}
示例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");
}
示例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);
}
}