CreateDeserializable() public static method

public static CreateDeserializable ( string name, IValue @object, INode parent, Bender.Nodes.Object.Context context, CachedMember member = null ) : ObjectNodeBase
name string
@object IValue
parent INode
context Bender.Nodes.Object.Context
member CachedMember
return ObjectNodeBase
Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
 private IEnumerable <INode> EnumerateNodes()
 {
     return(_members.Value.Where(x => !x.IsNodeType).Select(x => Context.Mode == Mode.Deserialize ?
                                                            NodeFactory.CreateDeserializable(x.Name, x.Value, this, Context, x.Member) :
                                                            NodeFactory.CreateSerializable(x.Name, x.Value, this, Context, x.Member))
            .Concat(EnumerateNodeInstances()).ToList());
 }
Beispiel #3
0
        protected override void AddNode(INode node, bool named, Action <INode> modify)
        {
            const string supported = "generic lists and generic enumerable interfaces";

            if (!SpecifiedType.IsGenericEnumerable)
            {
                throw new TypeNotSupportedException(
                          "non generic {0}".ToFormat(SpecifiedType.IsList ? "list" : "enumerable"),
                          SpecifiedType, Mode.Deserialize, supported);
            }

            if (_itemType.CanBeCastTo <INode>())
            {
                if (_itemType.Is <INode>() || _itemType.IsTypeOf(node))
                {
                    _list.Value.Add(node);
                }
            }
            else
            {
                if (Context.Options.TypeFilter.WhenNot(_itemType, Context.Options))
                {
                    return;
                }
                if (!ActualType.IsList)
                {
                    throw new TypeNotSupportedException(
                              "enumerable", ActualType, Mode.Deserialize, supported);
                }
                if (named)
                {
                    var itemName = GetItemName(_itemType);
                    if (!node.Name.Equals(itemName, Context.Options.Deserialization.NameComparison))
                    {
                        if (Context.Options.Deserialization.IgnoreUnmatchedArrayItems)
                        {
                            return;
                        }
                        if (!Context.Options.Deserialization.IgnoreArrayItemNames)
                        {
                            throw new InvalidItemNameDeserializationException(node.Name, itemName);
                        }
                    }
                }
                var value = ValueFactory.Create(_itemType);
                NodeFactory.CreateDeserializable(named ? Name : null, value, this, Context).Configure(modify);
                _list.Value.Add(value.Instance);
            }
        }