public static CreateDeserializable ( string name, IValue @object, INode parent, Bender.Nodes.Object.Context context, CachedMember member = null ) : |
||
name | string | |
@object | IValue | |
parent | INode | |
context | Bender.Nodes.Object.Context | |
member | CachedMember | |
return |
public static ObjectNodeBase CreateDeserializable(string name, IValue @object, INode parent,
Context context, CachedMember member = null)
{
var type = @object.SpecifiedType;
var kind = GetTypeKind(type, context.Options);
if (kind == TypeKind.Simple)
{
if (parent == null) throw new TypeNotSupportedException("simple type",
@object.SpecifiedType, Mode.Deserialize, "complex types");
return new ValueNode(context, name, @object, member, parent);
}
Func<object> factory = () => ObjectFactory.CreateInstance(type,
context.Options.Deserialization.ObjectFactory, parent.MapOrDefault(x => x.Value));
if (member == null || parent == null) @object.Instance = factory();
else @object = ValueFactory.Create(@object, factory);
switch (kind)
{
case TypeKind.Dictionary: return new DictionaryNode(context, name, @object, member, parent);
case TypeKind.Enumerable: return new EnumerableNode(context, name, @object, member, parent);
default: return new ObjectNode(context, name, @object, member, parent);
}
}
protected override void AddNode(INode node, bool named, Action <INode> modify) { if (!SpecifiedType.IsGenericDictionary) { throw new TypeNotSupportedException( "non generic dictionary", SpecifiedType, Mode.Deserialize, "generic dictionaries"); } if (node.IsNamed && _itemType.CanBeCastTo <INode>()) { if (_itemType.Is <INode>() || _itemType.IsTypeOf(node)) { _dictionary.Value.Add(node.Name, node); } } else { if (Context.Options.TypeFilter.WhenNot(_itemType, Context.Options)) { return; } var value = ValueFactory.Create(_itemType); NodeFactory.CreateDeserializable(node.Name, value, this, Context).Configure(modify); _dictionary.Value.Add(node.Name, value.Instance); } }