本文整理汇总了C#中ISerializer.UnSerialize方法的典型用法代码示例。如果您正苦于以下问题:C# ISerializer.UnSerialize方法的具体用法?C# ISerializer.UnSerialize怎么用?C# ISerializer.UnSerialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISerializer
的用法示例。
在下文中一共展示了ISerializer.UnSerialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Charge le fichier donné grâce au sérialiseur passé en paramètre
/// </summary>
/// <param name="filename">le fichier à ouvrir</param>
/// <param name="serializer">le sérialiseur utilisé</param>
/// <returns>les données du document</returns>
public static IDocumentData Load(string filename, ISerializer serializer)
{
if (filename == null)
throw new ArgumentNullException();
string loaded = LoadFile(filename);
//char[] separators = { '\n' };
//string[] serializedControls = loaded.Split(separators);
//IControlData[] controls = new IControlData[serializedControls.Count()];
string extension = Path.GetExtension(filename);
ControlDataWrapper[] controlwrappers = (ControlDataWrapper[]) serializer.UnSerialize(loaded);
IDocumentData model = new DocumentModel();
foreach (ControlDataWrapper wrapper in controlwrappers)
{
ControlData control = new ControlData(wrapper.name, wrapper.type);
PropertyDataWrapper[] datawrappers = wrapper.Properties;
foreach (PropertyDataWrapper datawrapper in datawrappers)
control.Properties.Add(datawrapper.Property, datawrapper.Value);
model.ControlsDictionary.Add(control.Name, control);
}
return model;
}
示例2: Save
/// <summary>
/// Sauvegarde le modèle dans le fichier spécifié avec le sérialiseur donné
/// </summary>
/// <param name="model">modèle à sauvegarder</param>
/// <param name="filename">nom du fichier de destination</param>
/// <param name="serializer">sérialiseur utilisé</param>
public static void Save(IDocumentData model, string filename, ISerializer serializer)
{
/*IControlData[] controls = new IControlData[model.ControlsDictionary.Count()];
for(int i=0; i<model.ControlsDictionary.Count(); i++)
{
string key = model.ControlsDictionary.Keys[i];
IControlData control = model.ControlsDictionary[key];
controls[i] = control;
}
string serialization = serializer.Serialize(controls);*/
string[][] test = new string[model.ControlsDictionary.Count][];
ControlDataWrapper[] controls = new ControlDataWrapper[model.ControlsDictionary.Count];
for(int indexControl=0; indexControl<model.ControlsDictionary.Count; indexControl++)
{
string key = model.ControlsDictionary.Keys[indexControl];
SortedList<string, string> properties = model.ControlsDictionary[key].Properties;
PropertyDataWrapper[] listproperties = new PropertyDataWrapper[properties.Count];
test[indexControl] = new string[properties.Count];
for(int indexProperty=0; indexProperty<properties.Count(); indexProperty++)
{
string property = properties.Keys[indexProperty];
string value = properties[property];
listproperties[indexProperty] = new PropertyDataWrapper(property, value);
}
string controlName = model.ControlsDictionary[key].Name;
string controlType = model.ControlsDictionary[key].Type;
controls[indexControl] = new ControlDataWrapper(controlName, controlType, listproperties);
}
string serialization = serializer.Serialize(controls);
ControlDataWrapper[] final = serializer.UnSerialize(serialization);
SaveFile(filename, serialization);
}