本文整理汇总了C#中IStorage.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# IStorage.Deserialize方法的具体用法?C# IStorage.Deserialize怎么用?C# IStorage.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorage
的用法示例。
在下文中一共展示了IStorage.Deserialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public object Deserialize(IStorage storage, Data.Node data, object result)
{
Kean.Collection.IList<Data.Node> nodes;
Reflect.Type type;
Reflect.Type elementType;
type = data.Type;
elementType = this.GetElementType(type);
if (data is Data.Collection)
nodes = (data as Data.Collection).Nodes;
else
{ // only one element so it was impossible to know it was a collection
nodes = new Kean.Collection.List<Data.Node>(data);
data.Type = data.OriginalType ?? elementType;
Uri.Locator locator = data.Locator.Copy();
locator.Fragment += "0";
data.Locator = locator;
}
if (result.IsNull())
result = this.Create(type, elementType, nodes.Count);
int i = 0;
foreach (Data.Node child in nodes)
{
int c = i++; // ensure c is unique in every closure of lambda function below
storage.Deserialize(child, elementType, d => this.Set(result, d, c));
}
return result;
}
示例2: Deserialize
public object Deserialize(IStorage storage, Data.Node data, object result)
{
result = data.Type.Create();
Reflect.Field[] fields = result.GetFields();
foreach (Data.Node node in (data as Data.Branch).Nodes)
{
string name = node.Name.Convert(storage.Casing, Casing.Camel);
Reflect.Field field = fields.Find(f => f.Name == name);
if (field.NotNull())
storage.Deserialize(node, field.Type, d => field.Data = d);
else
new Exception.FieldMissing(data.Type, name, node.Region).Throw();
}
return result;
}
示例3: Deserialize
public object Deserialize(IStorage storage, Data.Node data, object result)
{
if (result.IsNull())
try
{
result = data.Type.Create();
}
catch (System.MissingMethodException e)
{
if (data.Type == data.OriginalType)
new Exception.CreateAbstract(e, data.Type, data.Region).Throw();
else
new Exception.UnknownType(e, data.OriginalType, data.Region).Throw();
}
if (result.NotNull())
{
Reflect.Property[] properties = result.GetProperties();
if (data is Data.Branch)
foreach (Data.Node node in (data as Data.Branch).Nodes)
{
string name = node.Name.Convert(storage.Casing, Casing.Pascal);
Reflect.Property property = properties.Find(p =>
{
Kean.Serialize.ParameterAttribute[] attributes;
return (attributes = p.GetAttributes<Kean.Serialize.ParameterAttribute>()).Length > 0 && attributes[0].Name.NotEmpty() ? attributes[0].Name == node.Name : p.Name == name;
});
if (property.IsNull())
new Exception.PropertyMissing(data.Type, name, node.Region).Throw();
else if (property.Writable)
storage.Deserialize(node, property.Type, d => property.Data = d);
else if (property.Readable && (property.Type.Category == Reflect.TypeCategory.Class || property.Type.Category == Reflect.TypeCategory.Array || property.Type.Category == Reflect.TypeCategory.Interface))
storage.DeserializeContent(node.DefaultType(property.Type), property.Data);
else
new Exception.PropertyNotWriteable(data.Type, name, node.Region).Throw();
}
}
return result;
}